是否有可能使Tkinter按钮调用两个函数?
这样的事可能吗?:
from Tkinter import *
admin = Tk()
def o():
print '1'
def t():
print '2'
button = Button(admin, text='Press', command=o, command=t)
button.pack()
Run Code Online (Sandbox Code Playgroud)
小智 19
您可以使用 lambda 的示例方式,如下所示:
button = Button(text="press", command=lambda:[function1(), function2()])
Run Code Online (Sandbox Code Playgroud)
ick*_*fay 11
创建一个调用两者的新函数:
def o_and_t():
o()
t()
button = Button(admin, text='Press', command=o_and_t)
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用这个有趣的小功能:
def sequence(*functions):
def func(*args, **kwargs):
return_value = None
for function in functions:
return_value = function(*args, **kwargs)
return return_value
return func
Run Code Online (Sandbox Code Playgroud)
然后你可以像这样使用它:
button = Button(admin, text='Press', command=sequence(o, t))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13916 次 |
| 最近记录: |