-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaufgabe5.py
46 lines (35 loc) · 1.22 KB
/
aufgabe5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -----------------------------------------------------------------------------------------
# ------------------------------ Aufgabe 5: Ein Zähler
#
# Ziel: Erstelle ein Fenster mit einem Button, der bei jedem Klick einen Zähler um 1 erhöht.
#
# Anforderungen:
#
# Zeige einen Startwert von "0" in einem Label an.
# Füge einen Button hinzu mit der Beschriftung "Erhöhe".
# Jedes Mal, wenn der Button geklickt wird, erhöht sich der Zähler im Label um 1.
# -----------------------------------------------------------------------------------------
import tkinter as tk
def increment_counter():
global counter
counter += 1
label.config(text=str(counter))
def reset_counter():
global counter
counter =0
label.config(text=str(counter))
# Erstelle das Hauptfenster
window = tk.Tk()
window.title("Zähler")
# Initialisiere den Zähler
counter = 0
# Erstelle ein Label für den Zähler
label = tk.Label(window, text=str(counter))
label.pack()
# Erstelle einen Button
button = tk.Button(window.wm_minsize(200, 200), text="Erhöhe", command=increment_counter)
button.pack()
button1 = tk.Button(text="auf Null setzen", command=reset_counter)
button1.pack()
# Starte die Ereignisschleife
window.mainloop()