Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python杀死线程_Python_Multithreading_User Interface_Tkinter - Fatal编程技术网

如何使用python杀死线程

如何使用python杀死线程,python,multithreading,user-interface,tkinter,Python,Multithreading,User Interface,Tkinter,我正在用GUI(Tkinter)做一个随机数字猜测游戏,出现了运行时错误:线程只能启动一次。我想把线弄断,但我找不到任何办法。代码如下: def干管(c): 全局最大值,数字,猜测值,输入,l1,t1 如果c编号: 错误的结果=标签(root,text='error Answer!您的答案大于随机数'fg='red') elif答案

我正在用GUI(Tkinter)做一个随机数字猜测游戏,出现了
运行时错误:线程只能启动一次
。我想把线弄断,但我找不到任何办法。代码如下:

def干管(c): 全局最大值,数字,猜测值,输入,l1,t1 如果c编号: 错误的结果=标签(root,text='error Answer!您的答案大于随机数'fg='red') elif答案<编号: 错误结果=标签(root,text='error Answer!您的答案小于随机数'fg='red') 错误的结果网格(行=4) 时间。睡眠(3) 错误的结果。销毁()

在第一个函数(
main
)中,我调用线程;在第二个函数(
process
)中,我想杀死
线程(

,错误试图告诉您传递
命令=t1.start
将导致调用
start()
在同一
t1
实例上,每次按下按钮。在Python中,不能在同一线程实例上多次调用
thread.start()
。更改以下行:

        ...
        print(number)

        t1 = threading.Thread(target=lambda: process(int(guess_num.get())))
        l1 = Label(root, text='Whats the number?')
        guess_num = Entry(root, bd=3)
        enter = Button(root, text='Enter', command=t1.start)
        ...

        ...
        print(number)

        def process_in_thread():
            t1 = threading.Thread(target=lambda: process(int(guess_num.get())))
            t1.start()

        l1 = Label(root, text='Whats the number?')
        guess_num = Entry(root, bd=3)
        enter = Button(root, text='Enter', command=process_in_thread)
        ...