I coded tkinter GUI, which have some entry fields and does some operations after clicking "Start" button. I had a problem with "No response" GUI windows crash while executing these operations. I also wanted to have a label in GUI which informs about current status of these operations, so I/ve decided to use threads. Now the problem is, that after clicking "Start" button, thread is created and in case of some exceptions (created to avoid input errors) I have no possibility to click it again because of 'threads can only be started once' error. I have tried to use .join() on thread in case of exception, but 'current thread cannot be joined'.
import customtkinter
import threading
import tkinter
class MyGui:
def __init__(self, app):
self.app = app
self.entry_1 = customtkinter.CTkEntry(master=self.app, placeholder_text="Enter even number")
self.entry_1.pack(pady=10, padx=10)
self.button_1 = customtkinter.CTkButton(master=self.app, text="Start", command=threading.Thread(target=self.button_callback).start)
self.button_1.pack(pady=10, padx=10)
def is_even(self):
if int(self.entry_1.get()) % 2 != 0:
raise ValueError("Not even number")
else:
print("Even indeed")
def button_callback(self):
try:
self.is_even()
except ValueError:
return tkinter.messagebox.showerror("Error", "Error message")
app = customtkinter.CTk()
running = MyGui(app)
app.mainloop()
I am not able to correct my input mistakes, because I can't run them anymore, I need to turn off/on my GUI in case to do that. Could tell me how to error thread or how to achieve my goal some other way?