-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu_Class.py
138 lines (99 loc) · 4 KB
/
Menu_Class.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
from tkinter import *
import os
from PIL import ImageTk, Image
# @desc: Class to config the menu
# @param: Choice of window options (string)
class show_window():
def __init__(self,sOption="Menu"):
root = Tk()
app = Window(root)
if sOption == "Menu":
app.init_menu()
elif sOption=="Input":
app.init_input()
root.mainloop()
# @desc: Main Window class with visual settings
# @param: frame object from tk (TK object)
# @param: master frame for editing existing frames (TK object)
class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.master.resizable(width=False, height=False)
# @desc: initialise menu
# @param: give function name that gets activated by clicking start
def init_menu(self, start=None):
# Set size
self.master.geometry("600x400")
self.master.wm_attributes('-transparentcolor',self.master['bg'])
self.master.configure(background='snow')
# Change Title of master widget
self.master.title("Menu")
# allowing widget to take full space of root window
self.pack(fill=BOTH, expand=1)
# create menu bar
self.init_menu_bar()
# create grid
rows = 0
while rows < 50:
self.master.rowconfigure(rows, weight=1)
self.master.columnconfigure(rows, weight=1)
rows += 1
# Setting background image
img = Image.open(str(os.getcwd()) + "\\Config images\\Shared logo.gif")
img = img.resize((470, 120),Image.ANTIALIAS).convert("RGBA")
bg_img = Image.open((str(os.getcwd()) + "\\Config images\\bg_menu.gif"))
bg_img.paste(img, (230, 220), img)
background_image = ImageTk.PhotoImage(bg_img)
background_label = Label(self, image=background_image)
background_label.image = background_image
background_label.place(x=0, y=0, relwidth=1, relheight=1)
# creating quit button
quitButton = Button(self, text="Quit", command=self.client_exit,height=2, width=15, bg="white")
quitButton.place(x=20,y=340)
# creating start button
startButton = Button(self, text="Start", command=start, height=2, width=15, bg="white")
startButton.place(x=470, y=340)
# @desc: initialise menu bar
def init_menu_bar(self):
# create bar
menu = Menu(self.master)
self.master.config(menu=menu)
# create menu for in the bar
file = Menu(menu, tearoff=False)
file.add_command(label="Exit", command=self.client_exit)
# add menu to the bar
menu.add_cascade(label="File", menu=file)
# create menu for the bar
info = Menu(menu, tearoff=False)
info.add_command(label="Contact", command=self.show_Contact)
info.add_command(label="About", command=self.show_About)
# add menu to bar
menu.add_cascade(label="Info", menu= info)
def show_About(self):
frame = Window(Toplevel())
frame.init_About()
def show_Contact(self):
frame = Window(Toplevel())
frame.init_Contact()
def init_About(self):
self.master.title("About")
self.init_menu_bar()
self.master.geometry("500x300")
# logo = Image.open((str(os.getcwd()) + "\\Config images\\Shared logo.gif"))
# logo = logo.resize((400, 120), Image.ANTIALIAS).convert("RGBA")
# logo = ImageTk.PhotoImage(logo)
# logo_Label = Label(self.master, image=logo)
# logo_Label.image = logo
# logo_Label.place(x=0,y=0)
canvas = Canvas(self.master, bg="snow", width=500, height=300)
canvas.pack()
img = ImageTk.PhotoImage(file=(str(os.getcwd()) + "\\About info\\Logo.png"))
canvas.create_image(0, 0, image=img)
def init_Contact(self):
self.master.title("Contact")
self.init_menu_bar()
self.master.geometry("500x300")
def client_exit(self):
exit()
show_window()