Stopwatch in python

Reply

Join Date: Oct 2009
Posts: 1
Reputation: rush_ik52 is an unknown quantity at this point 
Solved Threads: 0
rush_ik52 rush_ik52 is offline Offline
Newbie Poster

Stopwatch in python

 
0
  #1
31 Days Ago
hey guys.. I wana implement a stop watch in python... The timer turns on when my program starts and continuesly shows the time spent until the end of the program.. Can someone please help me with this..??
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,008
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 285
woooee woooee is offline Offline
Veteran Poster
 
0
  #2
30 Days Ago
First, you have to decide which GUI toolkit you want to use. Here's an example Google found using Tkinter http://code.activestate.com/recipes/124894/
Linux counter #99383
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,983
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 926
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite
 
0
  #3
30 Days Ago
To run the stopwatch in the background, you need to check out the Python module threading.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 188
Reputation: masterofpuppets is an unknown quantity at this point 
Solved Threads: 47
masterofpuppets's Avatar
masterofpuppets masterofpuppets is offline Offline
Junior Poster
 
0
  #4
30 Days Ago
hi here's my version of the stop watch. it is not the best one but you'll get the point. woooee's example is better though and I agree with vegaseat about the threading:

  1. from Tkinter import *
  2. import time
  3.  
  4. root = Tk(); root.title( "Stop Watch" ); root.geometry( "250x100+500+200" )
  5. c = Canvas( root, width = 250, height = 100 ); c.pack()
  6.  
  7. ms, seconds, minutes, hours = 0, 0, 0, 0
  8. on = True
  9.  
  10. def stopWatch():
  11. global seconds, minutes, hours, on, ms
  12. h = c.create_text( 95, 30, text = str( hours ) + " :", font = "Arial" )
  13. m = c.create_text( 120, 30, text = str( minutes ) + " :", font = "Arial" )
  14. s = c.create_text( 145, 30, text = str( seconds ) + " :", font = "Arial" )
  15. mSec = c.create_text( 165, 30, text = str( ms ), font = "Arial" )
  16. stopB = Button( c, text = "Stop", bd = 4, width = 10, command = stop ); stopB.place( relx = 1, x = -158, y = 55 )
  17. while on:
  18. time.sleep( 0.1 )
  19. ms += 1
  20. if ms == 10:
  21. ms = 0; seconds += 1
  22. if seconds == 60:
  23. seconds = 0; minutes += 1
  24. if minutes == 60:
  25. minutes = 0; hours += 1
  26. c.delete( h, m, s, mSec )
  27. h = c.create_text( 95, 30, text = str( hours ) + " :", font = "Arial" )
  28. m = c.create_text( 120, 30, text = str( minutes ) + " :", font = "Arial" )
  29. s = c.create_text( 145, 30, text = str( seconds ) + " :", font = "Arial" )
  30. mSec = c.create_text( 165, 30, text = str( ms ), font = "Arial" )
  31. c.update()
  32.  
  33. def stop():
  34. global on
  35. on = False
  36.  
  37. stopWatch()
  38. mainloop()
My site ->> http://8masterofpuppets8.webs.com/
"My belief is stronger than your doubt."
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 148
Reputation: snippsat is an unknown quantity at this point 
Solved Threads: 46
snippsat snippsat is offline Offline
Junior Poster
 
0
  #5
30 Days Ago
I have made an alramclock with wxpython before with stopclock(countdown) as one of the function.
So wxpython has this function build in "wxStopWatch"
http://www.tnir.org/~rae/wx/manuals/2.4.2/wx364.htm
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC