【发布时间】:2020-12-07 06:04:09
【问题描述】:
如果单击按钮,我想执行一项任务。我该怎么做呢?我可以使用两个单独的函数来执行任务,但我在'hey' 中的'if' 块之后有一大段代码,我不想再次输入整个内容。我的代码是:
from tkinter import *
root = Tk()
def hey():
if bt1 is clicked:
#do something
if bt2 is clicked:
#do something
#some piece of code
bt1 = Button(root, text = 'yes', command = hey)
bt2 = Button(root, text = 'no', command = hey)
bt1.pack()
bt2.pack()
【问题讨论】:
标签: python tkinter button click