-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlesson8_GUI.py
38 lines (24 loc) · 909 Bytes
/
lesson8_GUI.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
import tkinter
import random
from tkinter import messagebox
secret = random.randint(1,30)
#alles erstes das fesnter erstellen
window = tkinter.Tk()
#ein festner kann meherere elemente haben
hello_label = tkinter.Label(window, text="Hallo Welt!")
#vor es dargestellt wird, muss man es noch ins fenster "packen"
hello_label.pack()
guess = tkinter.Entry(window)
guess.pack()
def ButtonClick():
if int(guess.get()) == secret:
result_text = "You WIN"
elif int(guess.get()) > secret:
result_text = "WRONG: number is too high"
else:
result_text = "WRONG: number is too low"
messagebox.showinfo(title="result", message = result_text)
submit_button = tkinter.Button(window, text = "Submit", command = ButtonClick) #command: funktion OHNE ()
submit_button.pack()
#damit das fesnter sich nicht gleich selbst beendet, muss es in der mainloop laufen
window.mainloop()