##April-May 2010 ##CSC323 ##The GUI for the Main Menu for ZeroLife from tkinter import * from ButtonCreator import * import BoardScreen import BoardSetup import ShowSpecies import LoadGame from SpeciesDatabase import * import JoinNetworkGame import Credits def run(event=None): """Creates and runs the main menu""" root = Tk() menu = MenuFrame(root) root.mainloop() class MenuFrame: """Create and fill the Frame that represents the main menu""" def __init__(self, parent, width=480, height=600): 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="Welcome to ZeroLife.\n", fg="black") title.pack(fill=X, side=TOP) """Build an empty frame for padding.""" self.padding = Frame(self.parent, width=width, height=30, bg="darkblue") self.padding.pack(fill=BOTH, side=TOP, expand=YES) self.container = ButtonContainer(self.parent) class ButtonContainer: """Creates a frame to contain and the main menu buttons and fills them""" def __init__(self, parent, width = 2000, bg = "darkblue"): width = width bg = bg self.container = Frame(parent, width=width, bg="darkblue") self.container.pack(side = TOP, fill = BOTH, expand = YES) self.parent = parent self.specdb = SpeciesDatabase.getInstance() self.addButtons() def addButtons(self, option = 1): """Add Buttons to the container""" createGameButton = ButtonCreator(self.container, "Create a Game", \ self.createGame) loadGameButton = ButtonCreator(self.container, "Load a Game", \ self.loadGame) networkButton = ButtonCreator(self.container, "Enter a networked game",\ self.networkGame) specButton = ButtonCreator(self.container, "Species Manager", \ self.createSpecies) creditsButton = ButtonCreator(self.container, "Credits",\ self.showCredits) #prefButton = ButtonCreator(self.container, "Preferences") #aboutButton = ButtonCreator(self.container, "About") quitButton = ButtonCreator(self.container, "Quit", self.destroyParent) def destroyParent(self, event= None): """Callback method for the Quit Button to destroy the frame""" self.parent.destroy() def createGame(self, event = None): """Callback method for the create Game button""" self.destroyParent(event) BoardSetup.run() def loadGame(self, event = None): """callback method for the load game menu""" self.destroyParent(event) LoadGame.run() def createSpecies(self, event = None): """Callback method for the create species button""" self.destroyParent(event) ShowSpecies.run() def networkGame(self, event = None): self.destroyParent(event) JoinNetworkGame.run() def showCredits(self, event = None): self.destroyParent(event) Credits.run()