-
Notifications
You must be signed in to change notification settings - Fork 0
/
DesignManager.py
46 lines (41 loc) · 1.62 KB
/
DesignManager.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
#imports:
from tkinter import *
from tkinter.filedialog import asksaveasfile
from json import dump as jsonDump #for saving board as JSON format
from tkinter.ttk import *
try:
import sv_ttk
except:
pass
tk = Tk() #tk is master
try:
sv_ttk.use_light_theme() #set light theme of window
except:
pass
tk.resizable(height=False, width=False) #disable resizing window
tk.title("Design Manager: GameOfLIFE")
#create Checkbutton (cells)
cells = dict() #the format of this dictionary is like this: {!label:[cellvariable&location, dead or live]}
k = dict() #used for locating cell location from tkinter output like !label3. {!labeln:cellx_y}
for x in range(1, 21):
for y in range(1, 21):
cellname = "cell{x}_{y}".format(x=x, y=y)
globals()[cellname] = Checkbutton(tk) #create a label(cell) with the name from cellname string.
globals()[cellname].state(['!alternate'])
globals()[cellname].grid(row=x+1, column=y)
#cells[locals()[cellname]] = [cellname, "dead"]
cells[cellname] = "dead"
k[locals()[cellname]] = cellname
#Saving board as JSON file:
def Save():
filepath = asksaveasfile(defaultextension=".json", filetypes=[("JSON file", "*.json")])
for x in k.keys():
CellName = k[x]
if x.instate(['selected']):
cells[CellName] = "live"
else:
cells[CellName] = "dead"
jsonDump(cells, filepath) #savefile
Button(tk, text="Save Board", command=Save).grid(row=1, column=0) #create Save button
Button(tk, text="Quit", command=exit).grid(row=2, column=0) #create Save button
tk.mainloop()