首页 > 解决方案 > 带有单击按钮的 tkinter 定义

问题描述

我尝试让我的一个定义单击我的 GUI 的一个按钮来运行另一个定义:

def1():
    #### I don't know the code here

def2():
    print("Hello World")

window = Tk()

button1 = Button(window, text="click 2nd button", command = lambda: threading.Thread(target=def1).start())
button2 = Button(window, text="2nd button", command = lambda: threading.Thread(target=def2).start())

这只是一个简单的例子,我不能def2()直接运行def1(),因为第一个和第二个定义需要很多时间,我使用线程让两个定义同时运行。我需要类似click(button2)in 的东西def1()

标签: pythonmultithreadingtkinter

解决方案


推荐阅读