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.

# 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()

Here's an example I wrote up for you that should be helpful...

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..."
This question has already been answered. Start a new discussion instead.