Skip to content Skip to sidebar Skip to footer

I Get This Error "runtimeerror: Threads Can Only Be Started Once" When I Click Close And Then Click Run Again

import threading from tkinter import * running = False def run(): global running c = 1 running = True while running: print(c) c += 1 run_threa

Solution 1:

As the error said, terminated thread cannot be started again.

You need to create another thread:

import threading
from tkinter import *running=False

def run():
    globalrunning
    c =1running=True
    while running:
        print(c)
        c +=1

def start():
    if notrunning:
        # no thread isrunning, createnew thread andstart it
        threading.Thread(target=run, daemon=True).start()

def kill():
    globalrunningrunning=False

root = Tk()
button = Button(root, text='Run', command=start)
button.pack()
button1 = Button(root, text='close', command=kill)
button1.pack()
button2 = Button(root, text='Terminate', command=root.destroy)
button2.pack()
root.mainloop()

Post a Comment for "I Get This Error "runtimeerror: Threads Can Only Be Started Once" When I Click Close And Then Click Run Again"