Reputation: 477
I am getting this error when I am trying to open another window from the main window tkinter window, first time it is running perfectly and also performing tasks also but after 2 times it gives this error and whole program gets crashed and get closed down without any warning , I don't know that how to handle this error in python if there is any error handling technique for this please help me on this , in my case I am just calling the other tkinter window from main tkinter window ,I have tried very hard to solve this error but it's not getting resolved as it is coming again and again , tried all the methods given in previous posts but still it's coming , I know that tkinter is not thread safe but how to handle it any ideas, I am new to this ?
root=Tk(mt_debug=1)
root.geometry('454x567')
B=Button(root,text='Plot window',command=lambda: func3(parameter)).grid(row=1,column=2,padx=10,pady=10)
root.mainloop()
def func3(parameter):
threading.Thread(target=lambda: Plottingandselect(parameter)).start()
#using threading to call the
#another window due to which above error is coming after opening and
#closing it 2-3 times
def Plottingandselect(rollno):
window=Tk(mt_debug=1)
window.title("Marks Distribution")
Label(window, text=rollno).grid(row=1,column=2)
Label(window,text="X axis").grid(row=2,column=1)
Label(window, text="Marks",relief=SUNKEN).grid(row=3, column=1)
Label(window,text="Y axis").grid(row=2,column=3,padx=22)
OPTIONS1 = [
"Physics",
"Maths",
"Chemistry",
"Biology",
]
list1 = Listbox(window, selectmode="multiple", relief=SUNKEN, font=("Times New Roman", 10))
#then user will select above parameters and graphs will be plotted and
#it is plotting also perfectly multiple times also , but when i am closing
# this plotting window and again I select another roll number and do the
#same 2-3 times it gives the following error
# mt_debug I am using because I thought that mttkinter will handle it but it's not true
This is the error:
invalid command name "233512792_check_events"
while executing
"233512792_check_events"
("after" script)
Exception in Tkinter callback
Tcl_AsyncDelete: async handler deleted by the wrong thread
Tried many methods, now having no idea how to resolve it.
Upvotes: 1
Views: 4664
Reputation: 46687
For your case, you can simply use Toplevel
instead of Tk
inside Plottingandselect()
function and no threading is required:
def Plottingandselect(rollno):
window = Toplevel()
window.title("Marks Distribution")
...
...
root = Tk(mt_debug=1) # are you using mtTkinter?
root.geometry('454x567')
B = Button(root, text='Plot window', command=lambda: Plottingandselect(parameter)) # 'parameter' is not defined in your original code
B.grid(row=1, column=2, padx=10, pady=10)
root.mainloop()
Upvotes: 1