Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tkinter-如何根据选项菜单选择更新组合框值?_Python_User Interface_Tkinter_Combobox_Optionmenu - Fatal编程技术网

Python Tkinter-如何根据选项菜单选择更新组合框值?

Python Tkinter-如何根据选项菜单选择更新组合框值?,python,user-interface,tkinter,combobox,optionmenu,Python,User Interface,Tkinter,Combobox,Optionmenu,我正在寻求以下方面的帮助 我正在处理一个小项目,该项目要求根据用户在选项菜单中的选择更新组合框值 当前,组合框显示线程1的值,但在大多数情况下,它显示的值类似于带数字的PY(即PY_VAR2) 下面是我试图连接的这两个小部件的主要代码部分 提前感谢你的帮助 ### Option Menu Section thdTypeLabel = Label(thdParamsFrame, text="Thread Type") thdTypeLabel.grid(row=0, column=0, padx=

我正在寻求以下方面的帮助

我正在处理一个小项目,该项目要求根据用户在选项菜单中的选择更新组合框值

当前,组合框显示线程1的值,但在大多数情况下,它显示的值类似于带数字的PY(即PY_VAR2)

下面是我试图连接的这两个小部件的主要代码部分

提前感谢你的帮助

### Option Menu Section
thdTypeLabel = Label(thdParamsFrame, text="Thread Type")
thdTypeLabel.grid(row=0, column=0, padx=(30,10), pady=(10,10),sticky=E)

thdInitType = StringVar(thdParamsFrame)
thdInitType.set("Thread 1")
thdTypeMenu = OptionMenu(thdParamsFrame, thdInitType, "Thread 1","Thread 2", "Thread 3", command=thdTypeSelection)
thdTypeMenu.grid(row=0, column=1)
thdTypeMenu.configure(width=14)
组合框部分

thdInitTPI = StringVar()
thdTPICombo = ttk.Combobox(thdParamsFrame, width = 17, textvariable=thdInitTPI, values=TPIVals)

thdType = thdInitType.get()

if thdType == "Thread 1":
    thdTPICombo.config(values=['2','3','4','5','6','8','10','12','14','16'])
elif thdType == "Thread 2":
    thdTPICombo.config(values=['2','3','4','5','6','8','10','12','14','16'])
elif thdType =="Thread 3":
    thdTPICombo.config(values=['6','7','8','10','11','12','14','16','18','20'])

thdTPICombo.bind('<<ComboboxSelected>>',None)
thdInitTPI=StringVar()
thdTPICombo=ttk.Combobox(thdParamsFrame,width=17,textvariable=thdInitTPI,values=TPIVals)
thdType=thdInitType.get()
如果thdType==“线程1”:
thdTPICombo.config(值=['2'、'3'、'4'、'5'、'6'、'8'、'10'、'12'、'14'、'16')
elif thdType==“线程2”:
thdTPICombo.config(值=['2'、'3'、'4'、'5'、'6'、'8'、'10'、'12'、'14'、'16')
elif thdType==“线程3”:
thdTPICombo.config(值=['6'、'7'、'8'、'10'、'11'、'12'、'14'、'16'、'18'、'20')
thdTPICombo.bind(“”,无)

好吧,您有一个来自选项菜单的回调:
thdTypeSelection
所以只需更新那里的组合框:

def thdTypeSelection(event=None):
    thdType = thdInitType.get()
    if thdType == "Thread 1":
        thdTPICombo.config(values=['2','3','4','5','6','8','10','12','14','16'])
    elif thdType == "Thread 2":
        thdTPICombo.config(values=['2','3','4','5','6','8','10','12','14','16'])
    elif thdType =="Thread 3":
        thdTPICombo.config(values=['6','7','8','10','11','12','14','16','18','20'])

让我有点不安的是,选项菜单中已经选择了
线程1
,但组合框显示的是
TPIVals
,不管它们是什么

谢谢你的帮助。请参阅下面的其他评论。