-
Notifications
You must be signed in to change notification settings - Fork 0
/
tkinter-猜數字
40 lines (30 loc) · 841 Bytes
/
tkinter-猜數字
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
import tkinter as tk
import random
import tkinter.messagebox as mb
window = tk.Tk()
window.title('Guess number')
window.geometry('800x600')
window.configure(background='white')
header_label = tk.Label(window, text='')
header_label.pack()
input_entry = tk.Entry(window)
input_entry.pack()
result_label = tk.Label(text='')
result_label.pack()
def calculate():
n = random.randint(1, 100)
guess = int(input_entry.get())
while n != "guess":
if guess < n:
mb.showinfo('anwser','數字比較大喔!')
break
elif guess > n:
mb.showinfo('anwser','數字比較小喔!')
break
else:
output='bingo!'
mb.showinfo("anwser",output)
break
button = tk.Button(window, text='確定', command=calculate)
button.pack()
window.mainloop()