-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
152 lines (120 loc) · 5.1 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from random import randint
from PIL import Image
import customtkinter as ctk
from customtkinter import(
CTkButton,
CTkLabel,
CTkEntry,
CTkImage
)
trys = 3
num = randint(1,15)
mau = None
print(num)
class App():
def __init__(self):
global num,mau
self.sus = ctk.CTk()
self.sus.geometry("800x600")
self.sus.title("Đoán số")
self.sus.resizable(False, False)
# self.sus.bg_image = CTkImage(Image.open("bg.png"),size=(800,600))
# self.sus.bg_image_label = CTkLabel(self.sus, image=self.sus.bg_image,text = "")
# self.sus.bg_image_label.place(x=0, y=0)
self.sus.label = CTkLabel(self.sus,text = "Đoán số (1 - 15)", font = ("Consolas",18))
self.sus.label.pack(padx = 10, pady = 10)
self.sus.textbox = CTkEntry(self.sus, font = ("Consolas",20), width = 100, height = 10,justify='center')
self.sus.textbox.pack(padx = 10,pady = 10)
self.sus.ans = CTkEntry(self.sus,font = ("Consolas",20), state = "disable", height= 10, width= 500,justify='center')
self.sus.ans.pack(padx = 10, pady = 10)
mau = self.sus.ans.cget("fg_color")
self.sus.submit = CTkButton(self.sus, text = "Gửi", font = ("Consolas", 20), command = self.process_button)
self.sus.bind('<Return>',self.process_button)
self.sus.submit.pack(padx = 10, pady = 10)
self.sus.mainloop()
def process_button(self,*args):
global trys,num
check = False
try:
nums = int(self.sus.textbox.get())
except:
check = True
if check == False and trys != 0 and (nums >= 1 and nums <= 15):
trys -= 1
if nums < num:
self.trakq(f"Số cần tìm lớn hơn {nums}!","red")
if trys == 0:
self.hetluot()
elif nums > num:
self.trakq(f"Số cần tìm nhỏ hơn {nums}!","red")
if trys == 0:
self.hetluot()
elif nums == num:
self.trakq(f"Số bạn vừa tìm được là {nums}!","green")
self.thang()
else:
if trys == 0:
self.hetluot()
else:
self.sus.ans.configure(state = "normal")
self.trakq("Vui lòng nhập đúng định dạng!","red")
def hetluot(self):
global num
self.trakq(f"Bạn đã hết lượt chơi! Số cần tìm là: {num}","red")
self.thua()
def trakq(self,msg:str,mau:str):
self.sus.ans.configure(state = "normal")
self.sus.ans.delete("0","end")
self.sus.ans.insert("0",msg)
self.sus.ans.configure(state = "disabled",fg_color = mau)
def thang(self):
self.win = ctk.CTk()
self.win.geometry("250x250")
self.win.resizable(False, False)
self.sus.submit.configure(state = "disabled")
self.sus.textbox.configure(state = "disabled")
self.win.label = CTkLabel(self.win, text = "Bạn đã chiến thắng!", font = ("Consolas",20))
self.win.label.pack(padx = 10,pady = 10)
self.win.conti = CTkButton(self.win, text = "Chơi tiếp", font = ("Consolas",20),command = self.conti2).pack(padx = 10,pady = 10)
self.win.close = CTkButton(self.win, text = "Dừng lại", font = ("Consolas",20),command = self.close2).pack(padx = 10,pady = 10)
self.win.mainloop()
def thua(self):
self.dia = ctk.CTk()
self.dia.geometry("250x250")
self.dia.resizable(False, False)
self.sus.submit.configure(state = "disabled")
self.sus.textbox.configure(state = "disabled")
self.dia.label = CTkLabel(self.dia, text = "Bạn đã hết lượt chơi!", font = ("Consolas",20))
self.dia.label.pack(padx = 10,pady = 10)
self.dia.conti = CTkButton(self.dia, text = "Chơi tiếp", font = ("Consolas",20),command = self.conti).pack(padx = 10,pady = 10)
self.dia.close = CTkButton(self.dia, text = "Dừng lại", font = ("Consolas",20),command = self.close).pack(padx = 10,pady = 10)
self.dia.mainloop()
def close(self):
self.sus.destroy()
self.dia.destroy()
def close2(self):
self.sus.destroy()
self.win.destroy()
def conti(self):
global trys,mau,num
num = randint(1,15)
trys = 3
self.dia.destroy()
self.sus.submit.configure(state = "normal")
self.sus.textbox.configure(state = "normal")
self.sus.textbox.delete("0","end")
self.sus.ans.configure(state = "normal")
self.sus.ans.delete("0","end")
self.sus.ans.configure(state = "disabled",fg_color = mau)
def conti2(self):
global trys,mau,num
num = randint(1,15)
trys = 3
self.win.destroy()
self.sus.submit.configure(state = "normal")
self.sus.textbox.configure(state = "normal")
self.sus.textbox.delete("0","end")
self.sus.ans.configure(state = "normal")
self.sus.ans.delete("0","end")
self.sus.ans.configure(state = "disabled",fg_color = mau)
App()