问题描述
`enter code here`
from tkinter import *
from tkinter.ttk import *
def on_field_change(index,value,op):
choice=StringVar
print( "comboBox updated to ",c.get() ) # does print the updated values
#choice=c.get
#return(choice) # added a return for testing - not useful
chosen=StringVar
chosen=""
root = Tk()
root.geometry("400x200+10+10")
v = StringVar()
x = StringVar
chosen=StringVar
chosen=""
c = ComboBox(root,textvar=v,values=["foo","bar","baz"])
c.set('foog')
c.grid(row=0,column=1)
#choice_label = ttk.Label(text='choice='+c.get() ) #does not update
choice_label = Label(text= c.get ) #does not update
choice_label = Label(text= v ) #does not update
choice_label.grid(row=3,column=0)
quit_button = ttk.Button(root,text="QUIT")
quit_button.grid(row=4,column=0)
quit_button['command'] = root.destroy
v.trace('w',on_field_change)
print('the new v is : ',c.get()) # does not print updated values
#x=v.trace('w',on_field_change)
#print('the new choice is : ',x ) # does not print updated values
# try to use the selected item in another label and for a dictionary search
mainloop()
enter code here
将事件处理程序绑定到组合框的多个示例。几乎所有这些都只是从事件处理程序中打印选定的值。 其他方法将字符串变量跟踪到事件处理程序。
我不知道如何将返回的值输入主体。我的目标是使用它成为标签的文本,并成为字典中的索引或键。
建议表示赞赏。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)