Я новичок в программировании, у меня всего несколько месяцев обучения.Я пытаюсь создать простое приложение для подсчета времени, затрачиваемого на обучение.
Я использую приложение Tkinter Stopwatch, которое я нашел здесь: "https://www.geeksforgeeks.org/create-stopwatch-using-python/" Я немного изменил его для некоторых экспериментов и изменений QoL.
Моя идея - добавить" Повестку дня "кнопка, в которой я вижу общее время (разные сессии), которое я ввел. «Сброс» считается как другой сеанс обучения.
ВЫПУСК / ВОПРОС: «Повестка дня» возвращает странные числа, не связанные с общим числомсекунд, зарегистрированных в двух сеансах.
import tkinter as Tkinter
counter = 0
running = False
total = 0
def counter_label(label):
def count():
if running:
global counter
global total
# To manage the intial delay.
if counter == 0:
display = "Starting..."
else:
display = str(counter)
label['text'] = display # Or label.config(text=display)
# label.after(arg1, arg2) delays by
# first argument given in milliseconds
# and then calls the function given as second argument.
# Generally like here we need to call the
# function in which it is present repeatedly.
# Delays by 1000ms=1 seconds and call count again.
label.after(1000, count)
counter += 1
session = counter
total = session + session
# Triggering the start of the counter.
count()
def total_count():
global total
display = str(total)
label['text'] = display
# start function of the stopwatch
def Start(label):
global running
running = True
counter_label(label)
start['state'] = 'disabled'
stop['state'] = 'normal'
reset['state'] = 'normal'
# Stop function of the stopwatch
def Stop():
global running
start['state'] = 'normal'
stop['state'] = 'disabled'
reset['state'] = 'normal'
running = False
if running == False:
start['text'] = 'Resume'
# Reset function of the stopwatch
def Reset(label):
global counter
counter = 0
# If rest is pressed after pressing stop.
if running == False:
reset['state'] = 'disabled'
label['text'] = 'Welcome!'
start['text'] = 'Start'
# If reset is pressed while the stopwatch is running.
else:
label['text'] = 'Starting...'
def Agenda():
global total
start['state'] = 'normal'
stop['state'] = 'normal'
reset['state'] = 'normal'
global total
display = str(total)
label['text'] = display
root = Tkinter.Tk()
root.title("Stopwatch")
# Fixing the window size.
root.minsize(width=250, height=70)
label = Tkinter.Label(root, text="Welcome!", fg="black", font="Verdana 30 bold")
label.pack()
start = Tkinter.Button(root, text='Start',
width=15, command=lambda: Start(label))
stop = Tkinter.Button(root, text='Stop',
width=15, state='disabled', command=Stop)
reset = Tkinter.Button(root, text='Reset',
width=15, state='disabled', command=lambda: Reset(label))
agenda = Tkinter.Button(root, text='Agenda', width=15, command=Agenda)
start.pack()
stop.pack()
reset.pack()
agenda.pack()
root.mainloop()