Advertisement
here2share

# threading_multitask_countdown_demo.py

Jun 10th, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. # threading_multitask_countdown_demo.py
  2.  
  3. from Tkinter import *
  4. import tkMessageBox
  5. import threading
  6. import time
  7. root = Tk()
  8. root.geometry("450x250+300+300")
  9. root.title("Multitask Countdown")
  10. #print dir(root)
  11. def myloop():
  12.     global task
  13.     task += 1
  14.     def run():
  15.         count = 60
  16.         tr = task
  17.         while (count > -1) and root.wm_state():
  18.             msg='Thread #%d -- The count is: %d\n' %(tr,count)
  19.             print msg,
  20.             if tr == task:
  21.                 print
  22.             count -= 1
  23.             time.sleep(1)
  24.  
  25.         msg='Thread #%d -- The count has now ended\n' %(tr)
  26.         print msg,
  27.     thread = threading.Thread(target=run)
  28.     thread.start()
  29. def mymessage():
  30.     tkMessageBox.showinfo(title="Alert", message="Hello World!")
  31.  
  32. task = 0
  33. buttonLoop = Button(root, text="Start Loop", command=myloop)
  34. buttonLoop.place(x=5, y=15)
  35.  
  36. buttonMessage = Button(root, text="Start Loop", command=mymessage)
  37. buttonMessage.place(x=85, y=15)
  38.  
  39.  
  40. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement