The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Hassaan Aslam (1) [Avatar] Offline
I have a made a timer in python, it starts the timer when we give it input from keyboard "1". now i want to stop the timer ans start again it by giving input "0" and 1" respectively, when i put input 0 the miner must pause and the start again from its paused value.
the code is given below.
from Tkinter import *
def update_timeText():
if (state):
global timer
# Every time this function is called,
# we will increment 1 centisecond (1/100 of a second)
timer[2] += 1
# Every 100 centisecond is equal to 1 second
if (timer[2] >= 45):
timer[2] = 0
timer[1] += 1
# Every 60 seconds is equal to 1 min
if (timer[1] >= 60):
timer[0] += 1
timer[1] = 0
# We create our time string here
timeString = pattern.format(timer[0], timer[1], timer[2])
# Update the timeText Label box with the current time
# Call the update_timeText() function after 1 centisecond
root.after(10, update_timeText)

# To start the kitchen timer
def start():
global state
state = True
# To pause the kitchen timer
def pause():
global state
state = False
# To reset the timer to 00:00:00
def reset():
global timer
timer = [0, 0, 0]
# To exist our program
def exist():

# Simple status flag
# False mean the timer is not running
# True means the timer is running (counting)
state = False
root = Tk()

root.wm_title('Machine Stoppage time')

# Our time structure [min, sec, centsec]
timer = [0, 0, 0]
# The format is padding all the
pattern = '{0:02d}:{1:02d}:{2:02d}'
# Create a timeText Label (a text box)
timeText = Label(root, text="00:00:00", font=("Century Gothic", 75))
resetButton = Button(root, text='Reset', command=reset)
quitButton = Button(root, text='Quit', command=exist)
var1 = input('Enter your input 1 for start 0 for stop:')
if var1==0:
state = False
state = True