Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.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 Tkinter-关键字参数重复_Python 3.x_Tkinter - Fatal编程技术网

Python 3.x Tkinter-关键字参数重复

Python 3.x Tkinter-关键字参数重复,python-3.x,tkinter,Python 3.x,Tkinter,尝试搜索此错误,目前在我的朋友程序帮助解决次要问题之前创建了一个解决窗口当前在一行中尝试使用两个命令时遇到问题可能是一个简单的解决方法了解我,如果有人可以帮助我解决问题,那将是史诗 这是密码 res1 = tkinter.Button(settings, text="800x600", fg="ghost white" , bg="grey10", font=(16), command=resolution1, command=close_window) res2 = tkinter.Butto

尝试搜索此错误,目前在我的朋友程序帮助解决次要问题之前创建了一个解决窗口当前在一行中尝试使用两个命令时遇到问题可能是一个简单的解决方法了解我,如果有人可以帮助我解决问题,那将是史诗

这是密码

res1 = tkinter.Button(settings, text="800x600", fg="ghost white" , bg="grey10", font=(16), command=resolution1, command=close_window)
res2 = tkinter.Button(settings, text="1024x768", fg="ghost white" , bg="grey10", font=(16), command=resolution2, command=close_window)
res3 = tkinter.Button(settings, text="1280x720", fg="ghost white" , bg="grey10", font=(16), command=resolution3, command=close_window)
res4 = tkinter.Button(settings, text="1920x1080", fg="ghost white" , bg="grey10", font=(16), command=resolution4, command=close_window)
如果你需要完整的代码,就大声喊吧


非常感谢

将命令与按钮一起使用的最佳方法是使用按钮调用函数。在该函数中,您可以执行任意操作,包括调用多个函数:

def do_resolution1():
    resolution1()
    close_window()

def do_resolution2():
    resolution2()
    close_widnow()
...
res1 = tkinter.Button(..., command=do_resolution1)
res2 = tkinter.Button(..., command=do_resolution2)
您也可以编写一个函数,将另一个函数作为参数,运行它,然后调用close_window。然后,您可以使用lambda为每个按钮调用具有不同参数的函数:

我不建议初学者使用这种方法,因为lambda可能会让人困惑

def set_resolution(func):
    func()
    close_window()
...
res1 = tkinter.Button(..., command=lambda: set_resolution(resolution1))
res2 = tkinter.Button(..., command=lambda: set_resolution(resolution2))
...

它抱怨您分配了两次命令属性。如果您希望命令执行多项操作,则需要调用函数并让函数执行多项操作。干杯!意识到了这一点!谢谢你,我有一个单行函数,所以是的,我的错,正如罗恩指出的,我可以在函数中添加关闭窗口命令,谢谢你!我知道这是一个愚蠢的错误,老实说,这是我编程tkinter的第一天,应该用常识啊哈