Skip to content

Instantly share code, notes, and snippets.

@Sulkar
Created August 12, 2017 20:15
Show Gist options
  • Save Sulkar/53cb894491de570cc849895de41937a9 to your computer and use it in GitHub Desktop.
Save Sulkar/53cb894491de570cc849895de41937a9 to your computer and use it in GitHub Desktop.
[python] non-blocking Tkinter thats uses .update_idletasks()
#
# non blocking Tkinter code -> uses of .update_idletasks()
#
import time
from tkinter import *
# Function: with timeout
def mySleep():
text.insert(INSERT, "start sleep\n")
root.update_idletasks() # updates the Tkinter form
time.sleep(2)
text.insert(INSERT, "end sleep\n")
root = Tk()
# Button
b1 = Button(root, text = "call mySleep", command = mySleep)
b1.grid(row=0,column=0)
# Textfield
text = Text(root, width=20)
text.grid(row=5,column=1)
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment