| | |
Stopwatch in python
![]() |
•
•
Join Date: Dec 2006
Posts: 1,008
Reputation:
Solved Threads: 285
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
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:
Python Syntax (Toggle Plain Text)
from Tkinter import * import time root = Tk(); root.title( "Stop Watch" ); root.geometry( "250x100+500+200" ) c = Canvas( root, width = 250, height = 100 ); c.pack() ms, seconds, minutes, hours = 0, 0, 0, 0 on = True def stopWatch(): global seconds, minutes, hours, on, ms h = c.create_text( 95, 30, text = str( hours ) + " :", font = "Arial" ) m = c.create_text( 120, 30, text = str( minutes ) + " :", font = "Arial" ) s = c.create_text( 145, 30, text = str( seconds ) + " :", font = "Arial" ) mSec = c.create_text( 165, 30, text = str( ms ), font = "Arial" ) stopB = Button( c, text = "Stop", bd = 4, width = 10, command = stop ); stopB.place( relx = 1, x = -158, y = 55 ) while on: time.sleep( 0.1 ) ms += 1 if ms == 10: ms = 0; seconds += 1 if seconds == 60: seconds = 0; minutes += 1 if minutes == 60: minutes = 0; hours += 1 c.delete( h, m, s, mSec ) h = c.create_text( 95, 30, text = str( hours ) + " :", font = "Arial" ) m = c.create_text( 120, 30, text = str( minutes ) + " :", font = "Arial" ) s = c.create_text( 145, 30, text = str( seconds ) + " :", font = "Arial" ) mSec = c.create_text( 165, 30, text = str( ms ), font = "Arial" ) c.update() def stop(): global on on = False stopWatch() mainloop()
•
•
Join Date: Aug 2008
Posts: 148
Reputation:
Solved Threads: 46
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
So wxpython has this function build in "wxStopWatch"
http://www.tnir.org/~rae/wx/manuals/2.4.2/wx364.htm
![]() |
Similar Threads
- My python program/function! (Python)
- python stopwatch (Python)
- News Story: It’s Like AJAX for Ruby and Python (Ruby)
- News Story: 450 bugs consumed by Python (Python)
- Code Snippet: Mortgage Calculator (Python) (Python)
Other Threads in the Python Forum
- Previous Thread: Problem with sys.path.append
- Next Thread: [RELEASE] City of Warscape
| Thread Tools | Search this Thread |
abrupt accessdenied anti apache application approximation argv array beginner book builtin calculator change converter countpasswordentry curved dan08 dictionaries dictionary dynamic edit enter examples file float format function gui heads homework import inches input java keyboard lapse launcher library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pyopengl python random recursion redirect remote reverse scrolledtext session simple software sprite statictext statistics string strings syntax table terminal text textarea threading time tlapse trick tuple tutorial twoup ubuntu unicode unit urllib urllib2 variable wordgame wxpython






