Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/python-igra-tetris/main_lesson_2.py
5925 views
1
from tkinter import *
2
from tkinter import messagebox
3
4
W, H = 10, 20
5
TILE = 45
6
GAME_RES = W * TILE, H * TILE
7
RES = 750, 940
8
FPS = 60
9
10
11
def on_closing():
12
if messagebox.askokcancel("Выход из приложения", "Хотите выйти из приложения?"):
13
tk.destroy()
14
15
16
tk = Tk()
17
tk.protocol("WM_DELETE_WINDOW", on_closing)
18
tk.title("Tetris")
19
tk.resizable(0, 0)
20
tk.wm_attributes("-topmost", 1)
21
#tk.iconbitmap("bomb-3175208_640.ico")
22
23
canvas = Canvas(tk, width=RES[0], height=RES[1], bg="red", highlightthickness=0)
24
canvas.pack()
25
26
img_obj1 = PhotoImage(file="img/bg.png")
27
canvas.create_image(0, 0, anchor=NW, image=img_obj1)
28
29
img_obj2 = PhotoImage(file="img/bg2.png")
30
canvas.create_image(20, 20, anchor=NW, image=img_obj2)
31
32
grid = [canvas.create_rectangle(x * TILE, y * TILE, x * TILE+TILE, y * TILE+TILE) for x in range(W) for y in range(H)]
33
for item in grid:
34
canvas.move(item, 20, 20)
35
36
score = 0
37
record = "0"
38
39
canvas.create_text(505, 30,text="TETRIS", font=("WiGuru 2", 45),fill="red", anchor=NW)
40
canvas.create_text(535, 780,text="score:", font=("WiGuru 2", 40),fill="white", anchor=NW)
41
canvas.create_text(550, 840,text=str(score), font=("WiGuru 2", 40),fill="white", anchor=NW)
42
canvas.create_text(525, 650,text="record:", font=("WiGuru 2", 40),fill="white", anchor=NW)
43
canvas.create_text(550, 710,text=record, font=("WiGuru 2", 40),fill="gold", anchor=NW)
44
45
#canvas.create_rectangle(420,120,480,480, fill="darkgreen", outline="")
46
#canvas.create_text(200,500,text="Hello World!", font=("Arial", 40),fill="white")
47
48
49
tk.mainloop()
50
51