Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- root=Tk()
- def task():
- print "hello"
- root.after(2000,task) # reschedule event in 2 seconds
- root.after(2000,task)
- root.mainloop()
- def after(self, ms, func=None, *args):
- """Call function once after given time.
- MS specifies the time in milliseconds. FUNC gives the
- function which shall be called. Additional parameters
- are given as parameters to the function call. Return
- identifier to cancel scheduling with after_cancel."""
- import Tkinter
- import threading
- class MyTkApp(threading.Thread):
- def __init__(self):
- threading.Thread.__init__(self)
- self.start()
- def callback(self):
- self.root.quit()
- def run(self):
- self.root=Tkinter.Tk()
- self.root.protocol("WM_DELETE_WINDOW", self.callback)
- self.s = Tkinter.StringVar()
- self.s.set('Foo')
- l = Tkinter.Label(self.root,textvariable=self.s)
- l.pack()
- self.root.mainloop()
- app = MyTkApp()
- print 'now can continue running code while mainloop runs'
- import Tkinter
- import threading
- class MyTkApp(threading.Thread):
- def __init__(self):
- self.root=Tkinter.Tk()
- self.s = Tkinter.StringVar()
- self.s.set('Foo')
- l = Tkinter.Label(self.root,textvariable=self.s)
- l.pack()
- threading.Thread.__init__(self)
- def run(self):
- self.root.mainloop()
- app = MyTkApp()
- app.start()
- # Now the app should be running and the value shown on the label
- # can be changed by changing the member variable s.
- # Like this:
- # app.s.set('Bar')
- def task():
- #do stuff
- root.update()
- while 1:
- task()
Add Comment
Please, Sign In to add comment