想设置一个功能:
在 输入框entry里面输入任意值按回车保存以后,combobox会自动跳转至下一选项,还请各位赐教。
想设置一个功能:
在 输入框entry里面输入任意值按回车保存以后,combobox会自动跳转至下一选项,还请各位赐教。
收起
通过绑定entry的return事件,对combobox值索引,用try...except...处理索引越界等问题,当在entry中输入一个前值,combobox值自动跳转为下一个值。
import tkinter as tk
from tkinter import ttk
windows=tk.Tk()
var_Subject = tk.StringVar()
v = tk.StringVar()
subject_combobox = ttk.Combobox(windows, textvariable=var_Subject) # 科目
subject_combobox.grid(row=0,column=0)
subject_combobox['value'] = ('c语言', 'Python', 'C++', 'Java', 'php')
#subject_combobox.current(0)
subject_combobox['state'] = 'readonly'
ent=tk.Entry(windows)
ent.grid(row=1,column=0)
x = subject_combobox['value']
def on_change(ent):
try:
subject_combobox.current(x.index(ent.widget.get())+1)
except:
subject_combobox.current(0)
ent.bind("<Return>", on_change)
windows.mainloop()
报告相同问题?