| | |
Stopwatch in python
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2006
Posts: 1,054
Reputation:
Solved Threads: 297
0
#2 Oct 27th, 2009
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 Oct 27th, 2009
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()
0
#5 Oct 27th, 2009
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 |
Tag cloud for Python
alarm assignment avogadro beginner bluetooth character cmd code copy customdialog cx-freeze data decimals dictionary directory dynamic error examples excel exe file float format ftp function generator gnu graphics gui halp homework http ideas import input itunes java leftmouse line linux list lists logging loop module mouse number numbers output parsing path port prime program programming projects push py2exe pygame pyglet pyqt python random recursion recursive schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh stdout string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode update urllib urllib2 variable ventrilo verify vigenere webservice wikipedia windows wxpython xlib






