Text widget updates only after calling method exits (threading issue?)

mariox19 mariodiana at gmail.com
Tue Dec 11 20:58:37 EST 2007


Are Tkinter widgets running on their own thread?

If I try to make a simple application that will print the letters A to
Z to a Tkinter Text widget, and I space the printing of each letter by
1 second, it seems no text will appear in the Text widget until the
method exits.

Take a look at this snippet:

    # Assume I have created no threads other than the one that comes
with Main

    def printToTkinterTextWidget(text):
        """
        Prints A-Z to the Text widget, 1 letter per second.
        """
        # Problem: no text appears in the widget until 26 seconds has
elapsed
        for aNumber in range(65, 91):
            self.textWidget.insert(END, text)
            time.sleep(1)

If I am supposed to send messages to Tkinter objects only from the
main thread, how can I get the letters to appear 1 per second?

Thanks,

Mario




More information about the Python-list mailing list