-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.py
More file actions
69 lines (60 loc) · 2.95 KB
/
menu.py
File metadata and controls
69 lines (60 loc) · 2.95 KB
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
import tkinter as tk
from tkinter.ttk import Combobox, Style
from buildings import create_buildings
from main import *
from typing import Dict, Union
from buildings import Building, Defence
class Menu:
def __init__(self):
self.offset_x: int = 0
self.offset_y: int = 0
self.window: tk.Tk = tk.Tk()
self.canvas: tk.Canvas = tk.Canvas(self.window)
self.style: Style = Style()
self.style.configure("TCombobox", fieldbackground='red')
self.style.theme_use()
self.background: tk.PhotoImage = tk.PhotoImage(file="res/images/background.png")
self.ok_btn_image: tk.PhotoImage = tk.PhotoImage(file="res/images/ok_button.png")
self.quit_btn_image: tk.PhotoImage = tk.PhotoImage(file="res/images/x.png")
self.choice: Combobox = Combobox(self.window, values=list(range(1, 10)), state="readonly")
self.quit_btn: tk.Button = tk.Button(self.window,
bg="black",
activebackground="black",
borderwidth=0,
image=self.quit_btn_image,
command=lambda: [self.window.destroy()])
self.ok_btn: tk.Button = tk.Button(self.window,
bg="black",
activebackground="black",
borderwidth=0,
image=self.ok_btn_image,
command=lambda: [self.start()])
self.create_menu()
def drag_window(self, event):
x: int = self.window.winfo_pointerx() - self.offset_x
y: int = self.window.winfo_pointery() - self.offset_y
self.window.geometry(f'+{x}+{y}')
def click_window(self, event):
self.offset_x: int = event.x+event.widget.winfo_rootx()-self.window.winfo_rootx()
self.offset_y: int = event.y+event.widget.winfo_rooty()-self.window.winfo_rooty()
def create_menu(self):
self.window.geometry("+500+200")
self.window.resizable(width=False, height=False)
self.window.bind('<ButtonPress-1>', self.click_window)
self.window.bind('<B1-Motion>', self.drag_window)
self.window.overrideredirect(1)
self.window.wm_attributes("-topmost", "true")
self.canvas.config(width=709, height=266, highlightthickness=0)
self.canvas.pack()
self.canvas.create_image(354, 133, image=self.background)
self.choice.current(0)
self.choice.place(x=380, y=158)
self.quit_btn.place(x=652, y=27)
self.ok_btn.place(x=410, y=190)
def start(self):
buildings: Dict[str, Union[Building, Defence]] = create_buildings(int(self.choice.get()))
self.window.destroy()
MainWindow(buildings)
if __name__ == "__main__":
menu: Menu = Menu()
menu.window.mainloop()