##menu that allows the user to load a game from file from tkinter import * from ButtonCreator import * import BoardScreen import BoardSetup import ShowSpecies from SpeciesDatabase import * import LocalWorld import pickle import Menu def run(event=None): """creates a new menu for saving the game""" root = Tk() save = LoadFrame(root) root.mainloop() class LoadFrame: def __init__(self, parent, width = 300, height = 200): self.parent=parent self.parent.geometry(str(width)+"x"+str(height)) self.frame = Frame(self.parent, width=width,\ height=height, bg="darkblue") self.frame.pack() title = Label(self.frame, text="Load\n", fg="black") title.pack(fill=X, side=TOP) self.container = LoadContainer(self.parent) class LoadContainer: def __init__(self, parent, width =1000, bg="darkblue"): self.container = Frame(parent,width=width,bg=bg) self.container.pack(side = BOTTOM, fill = BOTH, expand = YES) self.parent = parent self.addEverything() def addEverything(self): self.addLoadEntryBox() self.addLoadCancel() def addLoadEntryBox(self): '''builds and adds an entry field that can be used to enter a file name''' self.entryContainer = Frame(self.container, width= 25,bg="darkblue") self.entryLabel = Label(self.entryContainer, text ="File Name: ",\ bg= "darkblue", fg ="white") self.entryLabel.pack(fill=Y, side=LEFT) self.loadEntry = Entry(self.entryContainer) self.loadEntry.pack(fill=Y, side=LEFT) self.entryContainer.pack(pady = 50) def addLoadCancel(self): '''adds the save and cancel buttons to the bottom of the menu''' self.lowerButtonFrame = Frame(self.container, bg="darkblue") self.loadButton = ButtonCreator(self.lowerButtonFrame, "Load",\ self.loadClick, packOption = LEFT,\ width=10) self.cancelButton = ButtonCreator(self.lowerButtonFrame,"Cancel",\ self.cancelClick, packOption = RIGHT,\ width=10) self.lowerButtonFrame.pack(side =BOTTOM, fill=BOTH) def loadClick(self, event=None): self.path=str(self.loadEntry.get()) print(self.path) self.parent.destroy() self.loadFile(self.path) def cancelClick(self, event=None): self.parent.destroy() Menu.run() def loadFile(self, path): f = open(path, 'rb') p = pickle.load(f) world = LocalWorld.LocalWorld.fromWorldSpec(p) BoardScreen.run(world.width, world.height, p.default, lworld=world) # f = f+"db" # db = pickle.load(f)