-
Notifications
You must be signed in to change notification settings - Fork 0
/
tkinter_numbers_game.py
54 lines (38 loc) · 1.27 KB
/
tkinter_numbers_game.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
import tkinter as tk
from random import randint
window=tk.Tk()
window.resizable(width=False, height=False)
window.geometry("400x150")
window.title(" Clicker")
buttons=[[tk.Button(window,text=str(randint(0,1000)),width=10, height=1) for i in range(5)]for j in range(5)]
label=tk.Label(window,text="0", width=10, anchor="center", justify=tk.CENTER)
c=0
a=True
#----grid
for i in range(len(buttons)):
for j in range(len(buttons[i])):
buttons[i][j].grid(row=j,column=i)
label.grid(row=5,column=2)
numbers=[int(n.cget("text")) for m in buttons for n in m]
def deactivate(*args):
global a
if a:
label.after(999,counter)
a=False
for i in [n for m in buttons for n in m]:
if i.cget("state")!=tk.DISABLED:
if i.cget("state")==tk.ACTIVE and int(i.cget("text"))==min(numbers):
numbers.remove(int(i.cget("text")))
i.config(state=tk.DISABLED)
else:
i.config(state=tk.NORMAL)
def counter():
global c
if len(numbers)==0:
label.after_cancel(counter)
else:
c+=1
label.config(text=str(c))
label.after(999,counter)
window.bind("<Button-1>", deactivate)
window.mainloop()