Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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 3.x 组合框虚拟事件_Python 3.x_Tkinter - Fatal编程技术网

Python 3.x 组合框虚拟事件

Python 3.x 组合框虚拟事件,python-3.x,tkinter,Python 3.x,Tkinter,每当我尝试使用ComboBox运行函数时,我必须在函数中包含一个我不使用的参数,这样它才能运行。我已经尝试打印参数,它显示了这个“VirtualEvent x=0 y=0” 我希望它能够在没有任何参数的情况下运行,但它将显示以下错误: TypeError:update_day()接受0个位置参数,但提供了1个 如何删除此1位置参数 def update_day(): some code to run. trying=ttk.Combobox(popup, font=("times", 14),

每当我尝试使用ComboBox运行函数时,我必须在函数中包含一个我不使用的参数,这样它才能运行。我已经尝试打印参数,它显示了这个“VirtualEvent x=0 y=0”

我希望它能够在没有任何参数的情况下运行,但它将显示以下错误:

TypeError:update_day()接受0个位置参数,但提供了1个

如何删除此1位置参数

def update_day():
some code to run.

trying=ttk.Combobox(popup, font=("times", 14), value=month_option, width=5, textvariable=var2, state="readonly")
trying.place(x=220, y=100)
trying.bind("<<ComboboxSelected>>", update_day)
def update_day():
一些要运行的代码。
trying=ttk.Combobox(弹出窗口,字体=(“times”,14),value=month\u选项,宽度=5,textvariable=var2,state=“只读”)
位置(x=220,y=100)
正在尝试.bind(“,update\u day)

将函数绑定到事件时,tkinter将始终向回调传递对象。按照约定,此对象名为
事件
,描述触发回调的事件

您无法阻止发送参数,尽管存在解决方法。最简单的方法是在函数定义中使参数成为可选的

例如:

def update_day(event=None):
    some code to run

上面的命令允许函数接受传递给它的事件对象,但也允许您在不使用事件对象的情况下直接调用函数(例如:
update\u day()

我可以问一下,与在Label、Button等中使用命令调用函数相比,ComboBox为什么会产生参数@BarnacleOwn:因为绑定就是这样工作的。当您将事件绑定到函数时,tkinter总是发送一个表示触发回调的事件的对象。这种行为不是ComboBox独有的。