第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在Python Tkinter中綁定ComboBox的ListBox

如何在Python Tkinter中綁定ComboBox的ListBox

莫回?zé)o 2023-12-26 15:00:12
我希望進(jìn)行一個(gè)綁定,允許我根據(jù)用戶按下的鍵放置某個(gè)值。這是我執(zhí)行此操作的示例代碼:from tkinter import *from tkinter import ttkv=Tk()combo = ttk.Combobox(values=['item1','item2','item3','item4'], state='readonly')combo.current(0)combo.pack()def function(Event):    if(Event.char in '1234'):        combo.set(f'item{Event.char}')combo.bind('<Key>', function)v.mainloop()他們會(huì)告訴我“如果這有效,你問(wèn)這個(gè)做什么?” 事實(shí)證明,如果部署了組合框,綁定就會(huì)停止工作。問(wèn)題如何解決?我知道這部分問(wèn)題不應(yīng)該問(wèn),因?yàn)樗c所討論的問(wèn)題無(wú)關(guān)。但我想問(wèn)一下,如果這個(gè)問(wèn)題有問(wèn)題,或者拼寫(xiě)錯(cuò)誤,或者其他什么,請(qǐng)告知?!叭绾翁岢鲆粋€(gè)好問(wèn)題”的頁(yè)面對(duì)我沒(méi)有幫助,因?yàn)閺奈业慕嵌葋?lái)看,我按照他們所說(shuō)的去做一切。我盡力使此處所寫(xiě)的內(nèi)容盡可能詳細(xì)且易于理解。希望您的理解,謝謝。
查看完整描述

1 回答

?
至尊寶的傳說(shuō)

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個(gè)贊


from tkinter import *

from tkinter import ttk


v=Tk()


# I create two test combobox

for _ in range(2):

? ? combo = ttk.Combobox(values=['item1','item2','item3','item4'], state='readonly')

? ? combo.current(0)

? ? combo.pack()


# I create a test entry to test if the function correctly recognizes when it should be executed

entrada = Entry()

entrada.pack()


def function(Event):

? ? """

? ? If Event.widget is a str and ends with ".popdown.f.l" I consider it to be the Listbox,

? ? I get the path of the Combobox it belongs to and convert it to a widget.

? ? Afterwards, I set the value of Event.widget to that of the supposed combobox.

? ? """

? ? if(isinstance(Event.widget, str) and Event.widget.endswith(".popdown.f.l")):

? ? ? ? Event.widget = v._nametowidget(Event.widget[:-len(".popdown.f.l")])


? ? ? ??

? ? # If Event.widget is not a Combobox, it stops the execution of the function.

? ? if(not isinstance(Event.widget, ttk.Combobox)):

? ? ? ? return


? ? if(Event.char in '1234'):

? ? ? ? Event.widget.set(f'item{Event.char}')


v.bind_all('<Key>', function)

v.mainloop()


查看完整回答
反對(duì) 回復(fù) 2023-12-26
  • 1 回答
  • 0 關(guān)注
  • 169 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)