First of all, I know Tkinter isn't thread safe and this problem has something to do with that but I wanted to find out formally why this code makes a window that displays but is unresponsive.
from Tkinter import *
root = Tk()
c = Canvas()
c.pack()
c.create_line(10,10, 30, 30)
root.update()
I want to know why it crashes. I know the last line should contain a mainloop() but if as this post says mainloop just continuously calls the two methods there is no reason the above code should be unresponsive.
update()
just processes events once.mainloop()
(as the name implies) is a loop that continuously processes events.In your code you call
root.update()
only once, that's why your program becomes unresponsive or terminates.Put the call to
root.update()
in awhile
loop, and it will work as expected:However, if this solves your problem, probably you just want to call
root.mainloop()
.