可以使用 lambda 表达式来同时实现两个命令,例如:

from tkinter import *

def command1():
    print('Command 1 executed')

def command2():
    print('Command 2 executed')

root = Tk()

button = Button(root, text='Click me', command=lambda: (command1(), command2()))
button.pack()

root.mainloop()

在这个例子中,lambda 表达式同时调用了两个函数,即 command1 和 command2。当按钮被点击时,这两个函数都会被执行。

使用 Lambda 表达式在 Tkinter 按钮中同时执行多个命令

原文地址: https://www.cveoy.top/t/topic/oiqR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录