| | |
Threads? help
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 13
Reputation:
Solved Threads: 0
Hi, how would I get the timer() class to change time display()'s self.time
I'm new to threads and classes and have been sitting here thinking about it for the last half hour and still have know idea
Thanks heaps for any help.
I'm new to threads and classes and have been sitting here thinking about it for the last half hour and still have know idea
Thanks heaps for any help.
python Syntax (Toggle Plain Text)
# Count down timer import time import threading loop = 1 class time_display(object): def __init__(self): self.time = 30 def print_time(self): while self.time > 0: print self.time raw_input("Push ENTER to re-check the time") class timer(threading.Thread): def run(self): while loop == 1: time.sleep(1.0) # Add something here to decrease the time by 1 timer1 = time_display() timer2 = timer() timer2.start() timer1.print_time() # I don't know the command to end threads but this sounds right? timer2.end()
•
•
Join Date: Jan 2009
Posts: 11
Reputation:
Solved Threads: 3
Here's an example I wrote up for you that should be helpful...
python Syntax (Toggle Plain Text)
import time import threading time_var = 0 class time_display(object): global time_var def __init__(self): global time_var time_var = 30 def print_time(self): global time_var print time_var class timer(threading.Thread): def run(self): while(True): global time_var time.sleep(1.0) time_var -= 1 timer1 = time_display() timer().start() while(time_var >= 0): timer1.print_time() raw_input("Push ENTER to re-check the time") print "Count down complete..."
![]() |
Similar Threads
- I want google to index forum threads (Search Engine Optimization)
- new way the threads are timed (DaniWeb Community Feedback)
- IE won't let me access threads. Could someone email me a solution please? (Web Browsers)
Other Threads in the Python Forum
- Previous Thread: glade-3 python treeview
- Next Thread: defining a block of text with wxpython
| Thread Tools | Search this Thread |
abrupt ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog decimals dictionaries dictionary directory drive dynamic error examples excel exe file float format function gnu graphics gui heads homework http ideas import input java launcher leftmouse line linux list lists logging loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyqt python random recursion schedule scrolledtext sqlite statistics stdout string strings sudokusolver sum table terminal text thread threading time tkinter tlapse tricks tuple tutorial twoup ubuntu unicode update urllib urllib2 variable ventrilo wikipedia windows write wxpython xlib





