按下按钮时有多个命令 [英] Have multiple commands when button is pressed
本文介绍了按下按钮时有多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在单击按钮时运行多种功能。例如,我希望我的按钮看起来像
I want to run multiple functions when I click a button. For example I want my button to look like
self.testButton = Button(self, text = "test",
command = func1(), command = func2())
当我执行此语句时,我得到一个错误,因为我无法两次为参数分配内容。如何使命令执行多个功能。
when I execute this statement I get an error because I cannot allocate something to an argument twice. How can I make command execute multiple functions.
推荐答案
您可以创建用于组合功能的通用功能,看起来可能像这样:
You could create a generic function for combining functions, it might look something like this:
def combine_funcs(*funcs):
def combined_func(*args, **kwargs):
for f in funcs:
f(*args, **kwargs)
return combined_func
然后您可以像这样创建按钮:
Then you could create your button like this:
self.testButton = Button(self, text = "test",
command = combine_funcs(func1, func2))
这篇关于按下按钮时有多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文