thread,time, sleep

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Nov 2007
Posts: 46
Reputation: nish88 is an unknown quantity at this point 
Solved Threads: 0
nish88's Avatar
nish88 nish88 is offline Offline
Light Poster

thread,time, sleep

 
0
  #1
Feb 25th, 2008
hi everyone....... i am writing a program where i have 2 ovals and i want my first oval to appear then after 2 seconds the second one...but am failing in doing this.
can anyone help me to do this please. thank you in advance
here is my code

from Tkinter import *
import Tkinter
import time
import thread

frame=Tkinter.Frame()
frame.pack()



canvas =Tkinter.Canvas(frame,bg = 'white',width=500, height=500)
canvas.pack()

def generate():
        
            canvas.create_oval(200,300,210,310) #my first oval
            time.sleep(2)
            canvas.create_oval(200,300,210,310) # my second oval
            
        
                


        
        
        

    
button=Tkinter.Button(frame,fg="blue", text="GENERATE", command=generate).pack()


mainloop()

the problem that i'm having with this is that the computer is waiting for 2 sec then displays both oval but me i want 1 at a time.....

someone please help me in doing this
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,297
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 178
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: thread,time, sleep

 
0
  #2
Feb 25th, 2008
Please use the proper code tags around your code. Don't quote the whole thing or your code tags won't work.

Proper code tags are
[code=python]
your code here
[/code]

Please format your code so it is somewhat readable. Also, since your ovals are equal, how would you know the difference?

This how you might do it:
  1. import Tkinter as tk
  2.  
  3. def generate():
  4. oval1()
  5. frame.after(2000, oval2)
  6.  
  7. def oval1():
  8. canvas.create_oval(200, 300, 210, 310, fill='red')
  9.  
  10. def oval2():
  11. canvas.create_oval(200, 300, 210, 310, fill='blue')
  12.  
  13. frame = tk.Frame()
  14. frame.pack()
  15.  
  16. canvas = tk.Canvas(frame, bg='white', width=500, height=500)
  17. canvas.pack()
  18.  
  19. button = tk.Button(frame, fg="blue", text="GENERATE", command=generate)
  20. button.pack()
  21.  
  22. frame.mainloop()
Last edited by sneekula; Feb 25th, 2008 at 11:18 am.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 46
Reputation: nish88 is an unknown quantity at this point 
Solved Threads: 0
nish88's Avatar
nish88 nish88 is offline Offline
Light Poster

Re: thread,time, sleep

 
0
  #3
Feb 26th, 2008
hi.... its very nice what u've given but i want to use the time.sleep() function as later on i will have to add more oval.can you please tell me. thnx..
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1976 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC