Re: Einstellbarer Timer für ein Projekt in der Arbeit
Verfasst: Mittwoch 29. August 2018, 17:37
Zeig doch, was Du bisher hast, damit man sehen kann, wo noch etwas fehlt.
Seit 2002 Diskussionen rund um die Programmiersprache Python
https://www.python-forum.de/
Code: Alles auswählen
from functools import partial
import tkinter as tk
def button_countdown(label, counter):
stand = counter.get() - 1
counter.set(stand)
label.configure(fg='red' if stand == 0 else 'black')
if stand > 0:
label.after(1000, button_countdown, label, counter)
def button_start(label, counter):
label.after(1000, button_countdown, label, counter)
def button_reset(label, counter, start_value):
counter.set(start_value.get())
label.configure(fg='black')
def main():
root = tk.Tk()
root.title('Countdown')
root.geometry('790x425')
counter = tk.IntVar(root)
start_value = tk.IntVar(root, 10)
label = tk.Label(root, textvariable=counter, font=('Arial', 190))
label.grid(column=2,row=2)
tk.Button(root, text='START', command=partial(button_start, label, counter), font=('Arial', 32)).grid(column=1,row=3)
tk.Button(root, text='RESET', command=partial(button_reset, label, counter, start_value), font=('Arial', 32)).grid(column=3,row=3)
tk.Label(root, text='Startwert').grid(column=1,row=4)
tk.Entry(root, textvariable=start_value).grid(column=2,row=4)
root.mainloop()
if __name__ == '__main__':
main()