Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
stopwatch
#1
This is my stopwatch from using Tkinter. I was wondering if there was a way to save the times after you stop the stopwatch to some sort of list that will open back up with the program?

import tkinter as tink
count = -1
run = False
def var_name(mark):
def value():
if run:
global count
# Just beore starting
if count == -1:
show = "Starting"
else:
show = str(count)
mark['text'] = show
#Increment the count after
#every 1 second
mark.after(1000, value)
count += 1
value()

# While Running
def Start(mark):
global run
run = True
var_name(mark)
start['state'] = 'disabled'
stop['state'] = 'normal'
reset['state'] = 'normal'

# While stopped
def Stop():
global run
start['state'] = 'normal'
stop['state'] = 'disabled'
reset['state'] = 'normal'
run = False

# For Reset
def Reset(label):
global count
count = -1
if run == False:
reset['state'] = 'disabled'
mark['text'] = 'Welcome'
else:
mark['text'] = 'Start'

base = tink.Tk()
base.title("Alyssa's Stopwatch")
base.minsize(width=300, height=200,)
mark = tink.Label(base, text="Welcome", fg="#ff5ca5", font="Times 25 bold",bg="white")
mark.pack()
start = tink.Button(base, text='Start',fg="#c978ff",width=25, command=lambda: Start(mark))
stop = tink.Button(base, text='Stop', fg="#78b0ff", width=25, state='disabled', command=Stop)
reset = tink.Button(base, text='Reset', fg="#92fcbb",width=25, state='disabled', command=lambda: Reset(mark))
start.pack()
stop.pack()
reset.pack()
base.mainloop()
Reply
#2
you need to fix indentation
Reply
#3
Write to a file that you read when the program starts?
Reply
#4
(May-03-2020, 04:40 AM)Larz60+ Wrote: you need to fix indentation

my indentation is good in python I just copy and paste and it did some weird stuff. Do you know if the question I asked is possible?

(May-03-2020, 04:49 AM)ndc85430 Wrote: Write to a file that you read when the program starts?

yeah so like, something would save all of the stopwatch times to a list and that list could open back up with the program next time.. if that makes sense?
Reply
#5
when it is within proper code tags (as it is now), you can fix the indentation.
if posted within code tags, it will maintain indentation. so it may be easier to edit post and replace code (within python tags)
Reply
#6
(May-04-2020, 01:42 AM)amschueller Wrote: yeah so like, something would save all of the stopwatch times to a list and that list could open back up with the program next time.. if that makes sense?

Ok, so try it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] disable/enable button | stopwatch proj robertofreemano 1 6,268 Jul-18-2018, 09:52 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020