我想要创建一个tkinter OptionMenu,当它被更改时可以编辑另一个OptionMenu。因此,我尝试创建一个command=参数,它使一个特定的命令在OptionMenu的每个更新上运行,就像我使用command=参数对按钮、spinbox等所做的那样。
tl.wktype = OptionMenu(tl,wktypevar, *wk_types,command=typeupdate)代码中的其他地方是typeupdate()命令--为了现在的调试目的。
def typeupdate():
typeval = tl.wktype.get()
print(typeval)异常python抛出如下:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
return self.func(*args)
File "C:\Python33\lib\tkinter\__init__.py", line 3300, in __call__
self.__callback(self.__value, *args)
TypeError: typeupdate() takes 0 positional arguments but 1 was giventypeupdate()认为给出了哪些位置参数,以及如何解决这个问题?
发布于 2013-08-31 15:10:26
它被赋予被点击的值。要演示该脚本,请考虑以下脚本:
from tkinter import Tk, OptionMenu, StringVar
root = Tk()
def func(val):
print(val)
var = StringVar()
OptionMenu(root, var, "one", command=func).grid()
root.mainloop()当运行(单击选项菜单中的选项"one“)时,它会在终端中打印"one”。
因此,总之,将val (或任何其他参数名称)添加到函数声明中,它将工作:
def typeupdate(val):https://stackoverflow.com/questions/18549490
复制相似问题