Advertisement
sphinx2001

морской бой. 2 группа. часть 1

Nov 23rd, 2020
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import messagebox
  3. import time
  4.  
  5. def on_close_window():
  6.     global run_app
  7.     if messagebox.askokcancel("Морской бой", "Завершить работу программы?"):
  8.         run_app = False
  9.         game.destroy()
  10.  
  11. def draw_game_map():
  12.     for i in range(cells_w + 1):
  13.         canvas.create_line(cell_size_w * i, 0, cell_size_w * i, size_w)
  14.     for i in range(cells_h + 1):
  15.         canvas.create_line(0, cell_size_h * i, size_h, cell_size_h * i)
  16.  
  17. size_w = 700
  18. size_h = 700
  19. cells_w = cells_h = 10
  20. cell_size_w = size_w // cells_w
  21. cell_size_h = size_h // cells_h
  22.  
  23. _version = "0.1"
  24. run_app = True
  25. game = tk.Tk()
  26. game.protocol("WM_DELETE_WINDOW", on_close_window)
  27. game.resizable(0, 0) # Запрет изменения размеров окна
  28. game.wm_attributes("-topmost", 1) # окно приложение всегда на первом плане.
  29. game.title(f"Игра морской бой. Версия {_version}")
  30. canvas = tk.Canvas(game, width=size_w, height=size_h, bd=0, highlightthickness=0)
  31. canvas.create_rectangle(0, 0, size_w, size_h, fill="white")
  32. canvas.pack()
  33.  
  34. draw_game_map()
  35. while run_app:
  36.     if run_app:
  37.         game.update_idletasks()
  38.         game.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement