Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling an external function that contains 'time.sleep()' within a Tkinter window
    primarykey
    data
    text
    <p>I am attempting to call an external function from the press of a button in a Tkinter GUI; the function 'insert's into a Text element. This works perfectly; as long as it is not followed closely by time.sleep(). If it isn't followed, the text updates correctly; if it is, the text does not update, though the function still seems to be running the loop, as it will happily print text to the console.</p> <p>Here's my example script:</p> <pre><code>from Tkinter import * from time import sleep def test_function(gui_self): while True: print "Debug message" gui_self.main_.insert(END, "Test") class GUI: def __init__(self, master): frame = Frame(master, width=300, height=500) frame.pack() self.main_ = Entry(frame, width=80, justify=CENTER) self.main_.pack() test_function(self) root = Tk() application = GUI(root) root.mainloop() </code></pre> <p>This works well. However, changing test_function to the following seems to mess things up:</p> <pre><code>def test_function(gui_self): while True: print "Debug message" gui_self.main_.insert(END, "Test") sleep(5) </code></pre> <p>Any suggestions to fix whatever it is that I am doing wrong here? I'm sure it's just an issue that I, as a fairly basic level user, am not using the correct syntax for. </p> <p>As a side note, the 'sleep' command also seems to freeze the program entirely, which I find rather annoying and unattractive. Is there a method to pause the loop for a variably set (eg, var = 1(second)) amount of time, other than 'pipe'ing threads, that would be efficient and more.. clean? </p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload