def changeFrameQS ( self ) : if self.the_game is None: return orig_len = len ( self.my_games ) self.gameAdded() # make sure that game was added, if so, start new_len = len ( self.my_games ) if orig_len + 1 == new_len : g = self.my_games.pop ( new_len - 1 ) more_settings = copy.deepcopy ( self.additionalOptionsFrame.public_selected ) more_settings [ "timeout_limit" ] = self.additionalOptionsFrame.public_timeout if more_settings [ "timeout" ] : # convert n to integer rgx_float = re.compile ( "^[0-9]+(\.[0-9]+)?$" ) if not rgx_float.match(more_settings [ "timeout_limit" ]) : title = "Error: Additional Settings" message = "Games could not be started.\nError: Invalid timeout" wgt.ShowError( title, message, self.handler.root ) return more_settings [ "timeout_limit" ] = float(more_settings [ "timeout_limit" ]) more_settings [ "layout_chosen" ] = self.additionalOptionsFrame.public_layout if more_settings [ "timeout" ] and more_settings [ "timeout_limit" ] <= 0 : title = "Error: Additional Settings" message = "Games could not be started.\nError: Invalid timeout" wgt.ShowError( title, message, self.handler.root ) return pcs = [ pc.copyDict() for pc in self.my_pause_conditions ] self.saveSettings() self.the_game.process_settings ( [ g ], more_settings, pcs ) self.the_game.gameStartRequested () self.handler.showFrame(2)
def changeFrameStart ( self ) : if self.the_game is None: return games = [ g.copy() for g in self.my_games ] more_settings = copy.deepcopy ( self.additionalOptionsFrame.public_selected ) more_settings [ "timeout_limit" ] = self.additionalOptionsFrame.public_timeout if more_settings [ "timeout" ] : # convert n to integer rgx_float = re.compile ( "^[0-9]+(\.[0-9]+)?$" ) if not rgx_float.match(more_settings [ "timeout_limit" ]) : title = "Error: Additional Settings" message = "Games could not be started.\nError: Invalid timeout" wgt.ShowError( title, message, self.handler.root ) return more_settings [ "timeout_limit" ] = float(more_settings [ "timeout_limit" ]) more_settings [ "layout_chosen" ] = self.additionalOptionsFrame.public_layout if more_settings [ "timeout" ] and more_settings [ "timeout_limit" ] <= 0 : title = "Error: Additional Settings" message = "Games could not be started.\nError: Invalid timeout" wgt.ShowError( title, message, self.handler.root ) return if len(games) <= 0 : title = "Error: Games" message = "Games could not be started.\nError: No Games in queue" wgt.ShowError( title, message, self.handler.root ) return pcs = [ pc.copyDict() for pc in self.my_pause_conditions ] self.saveSettings() self.the_game.process_settings ( games, more_settings, pcs ) self.the_game.gameStartRequested () self.handler.showFrame ( 2 )
def pauseConditionAdded ( self, c = None, p = None ) : if c is None and p is None: c = {} p = [] keys = sorted ( list (self.addPauseOptionsFrame.public_selected.keys()) ) for k in keys : if self.addPauseOptionsFrame.public_selected[k] : if "Player" not in k : c[k] = int (self.addPauseOptionsFrame.public_values[k]) else : p.append ( self.addPauseOptionsFrame.public_values[k] ) else: continue elif c is None or p is None: return else: # check the players for i in p: if i not in PLAYERS and i != "Any AI": print("bad pause condition excluded:", p, c) print("uhoh", i) return # check the pause conditions valid_keys = self.addPauseOptionsFrame.public_selected.keys() for i in list(c.keys()): if i not in valid_keys: print("bad pause condition excluded:", p, c) return # check for invalid selection c_keys = list(c.keys()) if len( c_keys ) < 1 : title = "Error: Pause Condition Addtion" message = "No pause condition added.\nError: No conditions have been selected (checked)".format(k) wgt.ShowError( title, message, self.handler.root ) return for k in c_keys : if c[k] == ERROR_CODE : title = "Error: Pause Condition Addtion" message = "No pause condition added.\nError: Pause Condition missing value for: {}".format(k) wgt.ShowError( title, message, self.handler.root ) return b = BlueBox ( self.pcScrollFrame.interior ) new_pc = PauseConditionGUIData ( c, p, b ) new_pc.gui_box.delButton.command = partial ( self.deletePC, new_pc ) b.grid (sticky=tk.W) if self.dummyPCLabel is not None: self.dummyPCLabel.destroy() self.dummyPCLabel = tk.Label(self.pcScrollFrame.interior, bg = "white", text = "\n\n") self.dummyPCLabel.grid(sticky=tk.W) self.pcScrollFrame.set_scrollregion(vertical_buff=300) self.my_pause_conditions.append (new_pc) self.parent.update_idletasks()
def __init__ ( self, parent = None) : tk.Frame.__init__(self, parent) self.parent = parent bc = wgt.LIGHT_BLUE fnt = ( "Courier", 12 ) self.maxl = 34 self.config ( bg = bc, padx = 2, pady = 2, width = 500 ) self.config ( highlightbackground="white", highlightcolor="white", highlightthickness=2, bd= 0 ) self.myTopText = tk.StringVar() self.setTopText ( "game type num games", ) self.topLabel = tk.Label ( self, textvar = self.myTopText, anchor=tk.W, justify=tk.LEFT, bg = bc, font = fnt ) self.topLabel.grid ( row = 0, column = 0, columnspan = 8, sticky = tk.W ) self.delButton = wgt.ColoredButton ( self, "x", wgt.LIGHT_BLUE, wgt.RED, flash = True ) self.delButton.config ( font = BUTTON1_FONT, relief="flat", borderwidth=2 ) self.delButton.grid ( row = 0, column = 8 ) self.textLines = [] self.myText = tk.StringVar() self.setTextLines ( [ "player,"*50 ] ) self.myTextFrame = tk.Frame ( self, bg = bc, padx = 2, pady = 2 ) self.myTextLabel = tk.Label ( self.myTextFrame, textvar = self.myText, anchor=tk.W, justify=tk.LEFT, bg = bc, font = fnt ) self.myTextLabel.pack() self.myTextFrame.grid ( row = 1, column = 0, columnspan = 8 )
def killPressed(self): # only kill if there's something to kill and game is not already killed if not self.game.running or self.game.killed: return # pause the game during the resolution of the kill button pause = False if not self.paused: self.pausePressed() pause = True res = RedoneWidgets.askQuestion( "Kill Game", "Do you want to kill the game immediately?\n" "Note that ending running games may damage AIs.", self.root) if res == "yes": self.gameHandler.setupsPlaced = None self.gameHandler.setupLocations = None self.gameHandler.killButton.disable() self.statsHandler.killButton.disable() self.game.kill() self.gameHandler.setInstructionText("Game Killed") if self.paused: self.pausePressed() # unpause the game if we paused it if self.paused and pause: self.pausePressed()
def __init__(self, parent=None): tkinter.Frame.__init__(self, parent) self.parent = parent self.maxl = 45 #38 #for 11 bc = wgt.LIGHT_PURPLE fnt = ("Courier", 10) self.config(bg=bc, padx=2, pady=2, width=500) self.config(highlightbackground="white", highlightcolor="white", highlightthickness=2, bd=0) self.textLines = [] self.myText = tkinter.StringVar() self.setTextLines("") self.myTextFrame = tkinter.Frame(self, bg=bc, padx=2, pady=2) self.myTextLabel = tkinter.Label(self.myTextFrame, textvar=self.myText, anchor=tkinter.W, justify=tkinter.LEFT, bg=bc, font=fnt) self.myTextLabel.pack() self.myTextFrame.grid(row=0, column=0, columnspan=8) self.myClock = self.timeLabel = wgt.StopWatch(self) self.myClock.grid(row=1, column=0, columnspan=8)
def __init__(self, parent = None): # initialize UI object tk.Frame.__init__(self, parent) # store event handler to close later self.parent = parent self.config ( padx = 2, pady=2 ) self.pack ( fill="both", side=tk.BOTTOM ) self.playersFrame = wgt.ScrollableFrame(self) self.playersFrame.config( padx = 2, pady=2 ) self.playersFrame.canvas.config(height=200) self.players = PLAYERS + ["Select All"] playerCheckButtons = [] self.selected = {} cols = PLAYER_COLS for i in range ( len(self.players) ) : p = self.players[i] self.selected[p] = tk.BooleanVar() b = tk.Checkbutton ( self.playersFrame.interior, text = p, variable = self.selected[p], bg = "white" ) playerCheckButtons.append ( b ) b.grid ( row = int (i/cols), column = i%cols, sticky=tk.W ) if p == "Select All" : b.config ( command = self.selectAllPlayers ) self.gameStartFrame = tk.Frame ( self ) self.numGamesFrame = tk.Frame ( self.gameStartFrame ) self.numGamesLabel = tk.Label ( self.numGamesFrame, text = "Games: " ) self.numGamesLabel.pack ( side=tk.LEFT ) self.numGamesEntry = tk.Entry ( self.numGamesFrame, text="1" ) self.numGamesEntry.pack ( fill="both")#tk.X ) self.numGamesEntry.delete ( 0,tk.END ) self.numGamesEntry.insert ( 0, "1" ) self.startButton = wgt.ColoredButton ( self.gameStartFrame, "QuickStart", wgt.LIGHT_GREEN, "black", flash=True ) self.startButton.pack ( fill=tk.X, side=tk.BOTTOM ) self.startButton.config ( font = BUTTON2_FONT ) self.numGamesFrame.pack ( fill=tk.X,side=tk.BOTTOM ) self.gameStartFrame.pack ( fill=tk.X,side=tk.BOTTOM ) self.playersFrame.pack ( fill="both" )
def __init__(self, parent = None): # initialize UI object tk.Frame.__init__(self, parent) # store event handler to close later self.parent = parent self.config ( padx = 2, pady=2 ) self.pack ( side=tk.BOTTOM ) self.playersFrame = tk.Frame ( self ) self.players = PLAYERS + ["Human"] self.player1Text = tk.Label ( self.playersFrame, text = "Player 1:" ) self.player1Text.grid ( row = 0, column = 0, rowspan = 1, columnspan = 1, sticky = tk.W ) self.player1Type = tk.StringVar ( self ) self.player1Type.set(self.players[0]) self.o_player1 = tk.OptionMenu(self.playersFrame, self.player1Type, *self.players ) self.o_player1.grid ( row = 0, column = 1, rowspan = 1, columnspan = 10, sticky = tk.W ) self.player2Text = tk.Label ( self.playersFrame, text = "Player 2:" ) self.player2Text.grid ( row = 1, column = 0, rowspan = 1, columnspan = 1, sticky = tk.W ) self.player2Type = tk.StringVar ( self ) self.player2Type.set(PLAYERS[0]) self.o_player2 = tk.OptionMenu(self.playersFrame, self.player2Type, *PLAYERS ) self.o_player2.grid ( row = 1, column = 1, rowspan = 1, columnspan = 10, sticky = tk.W ) self.filler = tk.Label ( self.playersFrame, text="\n"*10 ) self.filler.grid ( row = 2, column = 0, rowspan = 1, columnspan = 1 ) self.numGamesFrame = tk.Frame ( self ) self.numGamesLabel = tk.Label ( self.numGamesFrame, text = "Games: " ) self.numGamesLabel.pack ( side=tk.LEFT ) self.plusButton = wgt.ColoredButton ( self.numGamesFrame, " + ", "black", "white", flash=True ) self.plusButton.config ( font=BUTTON1_FONT ) self.plusButton.pack ( side=tk.RIGHT ) self.numGamesEntry = tk.Entry ( self.numGamesFrame, text="1" ) self.numGamesEntry.pack ( fill="both")#tk.X ) self.numGamesEntry.delete ( 0,tk.END ) self.numGamesEntry.insert ( 0, "1" ) self.numGamesFrame.pack ( fill=tk.X,side=tk.BOTTOM ) self.playersFrame.pack ( fill="both" )
def createFrames ( self ) : #### # GUI # configure rows and columns of the main frame for r in range(23): self.parent.rowconfigure(r, weight=1) for c in range(2): if c > 0 : self.parent.columnconfigure(c, weight=1) else : self.parent.columnconfigure(c, weight=0) ########################## # left side -- queues and start # game queue self.gameQFrame = tk.Frame ( self.parent, highlightthickness = FRAME_BDR, highlightbackground="black" ) self.gameQFrame.grid ( row = 1, column = 0, rowspan = 8, columnspan = 1, sticky = tk.W+tk.E+tk.N+tk.S ) self.gameQLabel = tk.Label ( self.gameQFrame, text = "Game Queue", \ fg = FL_TEXT_COLOR, bg=FL_COLOR, borderwidth=FL_BD, relief=FL_STYLE, font=FL_FONT ) self.gameQLabel.pack ( side=tk.TOP, fill=tk.X ) self.gameQClearButton = wgt.ColoredButton ( self.gameQFrame, "Clear All Games", wgt.RED, "black", self.clearGameList, True ) self.gameQClearButton.config ( font = BUTTON2_FONT ) self.gameQClearButton.pack ( side=tk.BOTTOM, fill=tk.X, padx=2,pady=2 ) self.myGamesFrame = tk.Frame ( self.gameQFrame, bg="white",bd=5 ) self.gamesScrollFrame = wgt.ScrollableFrame ( self.myGamesFrame ) self.gamesScrollFrame.config( padx = 2, pady=2 ) self.gamesScrollFrame.canvas.config(height=300) self.myGamesFrame.pack ( fill="both" ) self.gamesScrollFrame.pack ( fill="both" ) # pause condition log self.pauseConditionsFrame = tk.Frame ( self.parent, highlightthickness = FRAME_BDR, highlightbackground="black" ) self.pauseConditionsFrame.grid ( row = 10, column = 0, rowspan = 8, columnspan = 1, sticky = tk.W+tk.E+tk.N+tk.S ) self.pauseConditionsLabel = tk.Label ( self.pauseConditionsFrame, text = "Pause Conditions", \ fg = FL_TEXT_COLOR, bg=FL_COLOR, borderwidth=FL_BD, relief=FL_STYLE, font=FL_FONT ) self.pauseConditionsLabel.pack ( side=tk.TOP, fill=tk.X ) self.pauseConditionsClearButton = wgt.ColoredButton ( self.pauseConditionsFrame, "Clear All Pause Conditions",\ wgt.RED, "black", self.clearPCList, True ) self.pauseConditionsClearButton.config ( font = BUTTON2_FONT ) self.pauseConditionsClearButton.pack ( side=tk.BOTTOM, fill=tk.X, padx=2,pady=2 ) self.myPCFrame = tk.Frame ( self.pauseConditionsFrame, bg="white",bd=5 ) self.pcScrollFrame = wgt.ScrollableFrame ( self.myPCFrame ) self.pcScrollFrame.config( padx = 2, pady=2 ) self.pcScrollFrame.canvas.config(height=200) self.myPCFrame.pack ( fill="both" ) self.pcScrollFrame.pack ( fill="both" ) # start button self.startButtonFrame = tk.Frame ( self.parent, bg="white" ) self.startButtonFrame.grid ( row = 18, column = 0, rowspan = 1, columnspan = 1, sticky = tk.E+tk.W ) self.startButton = wgt.ColoredButton ( self.startButtonFrame, "START", wgt.GREEN, "black", self.changeFrameStart, True ) self.startButton.config ( font = BUTTON1_FONT ) self.startButton.pack ( fill = tk.X ) ########################## # right side -- add game, additional settings, add pause conditions # add a game self.addGameFrame = tk.Frame(self.parent, bg = "black", padx = FRAME_BDR, pady=FRAME_BDR ) self.addGameFrame.grid(row = 1, column = 1, rowspan = 6, columnspan = 1, sticky = tk.W+tk.E+tk.N+tk.S) self.addGameType = tk.StringVar ( self.addGameFrame ) self.addGameType.set(GAME_TYPES[0]) self.addGameOptionMenu = tk.OptionMenu(self.addGameFrame, self.addGameType, *GAME_TYPES, command = self.addGameChanged ) self.addGameOptionMenu.config ( font=FL_FONT ) self.addGameOptionMenu.pack ( fill=tk.X, side=tk.TOP ) self.addGameOptionsWindow = QuickStartFrame ( self.addGameFrame ) self.addGameOptionsWindow.startButton.command = self.changeFrameQS # additional settings self.additionalSettingsFrame = tk.Frame(self.parent, padx = FRAME_BDR, pady=FRAME_BDR ) self.additionalSettingsFrame.grid(row = 7, column = 1, rowspan = 5, columnspan = 1, sticky = tk.W+tk.E+tk.N+tk.S) self.additionalSettingsLabel = tk.Label(self.additionalSettingsFrame, text = "Additional Settings", \ fg = FL_TEXT_COLOR, bg=FL_COLOR, borderwidth=FL_BD, relief=FL_STYLE, font=FL_FONT ) self.additionalSettingsLabel.pack ( fill=tk.X ) self.additionalOptionsFrame = AdditionalSettingsOptionsFrame ( self.additionalSettingsFrame ) self.additionalOptionsFrame.pack (side=tk.BOTTOM, fill="both") # add pause condition self.addPauseConditionsFrame = tk.Frame(self.parent, padx = FRAME_BDR, pady=FRAME_BDR ) self.addPauseConditionsFrame.grid(row = 13, column = 1, rowspan = 6, columnspan = 1, sticky = tk.W+tk.E+tk.N+tk.S) self.pcLabelFrame = tk.Frame(self.addPauseConditionsFrame) self.pcLabelFrame.pack(fill=tk.X) self.addPauseConditionPlus = wgt.ColoredButton ( self.pcLabelFrame, " "*1 + "+" + " "*1, "black", "white", flash=True ) self.addPauseConditionPlus.config ( font = BUTTON1_FONT ) self.addPauseConditionPlus.pack ( side=tk.LEFT ) self.addPauseConditionPlus.command = self.pauseConditionAdded self.addPauseConditionsLabel = tk.Label(self.pcLabelFrame, text = "Add Pause Conditions", \ fg = FL_TEXT_COLOR, bg=FL_COLOR, borderwidth=FL_BD, relief=FL_STYLE, font=FL_FONT ) self.addPauseConditionsLabel.pack ( fill=tk.X ) self.addPauseOptionsFrame = AddPauseOptionsFrame ( self.addPauseConditionsFrame ) self.addPauseOptionsFrame.pack (side=tk.BOTTOM, fill="both") self.dummyPCLabel = None self.dummyGameLabel = None # saved settings? self.loadSavedSettings()
def gameAdded ( self, t = None, n = None, p = None, box_needed = True ) : if t is None and n is None and p is None: t = self.addGameType.get() n = self.addGameOptionsWindow.get_num_games () p = self.addGameOptionsWindow.get_players () box_needed = self.addGameOptionsWindow.is_box_needed () elif t is None or n is None or p is None: return else : # check the players for i in p: if i not in PLAYERS and \ not (t == "Two Player" and i == "Human" and i == p[0] ): print("bad game excluded:", t,n,p) return # adjust the game type for quickstart if t == "QuickStart" : num_p = len ( p ) if num_p == 0 : # error wgt.ShowError( "Error: QuickStart", "Error: No players selected.", self.handler.root ) return elif num_p == 1 : # human versus agent p.append ( "human" ) t = "Two Player" else : # num_p can be classified as round robin t = "Round Robin" # convert n to integer rgx_int = re.compile ( "^[0-9]+$" ) if not rgx_int.match(n) : title = "Error: Game Addition" message = "No game added.\nError: Invalid number of games: {}".format(n) wgt.ShowError( title, message, self.handler.root ) return n = int ( n ) # verify valid number of games if n < 1 : title = "Error: Game Addtion" message = "No game added.\nError: Invalid number of games: {}".format(n) wgt.ShowError( title, message, self.handler.root ) return # verify valid players if p is None or p == [] : title = "Error: Game Addtion" message = "No game added.\nError: Not enough players." wgt.ShowError( title, message, self.handler.root ) return # limit human games to 1 if "human" in [l.lower() for l in p] and n != 1 : title = "Error: Game Addtion" message = "No game added.\nError: Human Games limited to 1, add separately for more." wgt.ShowError( title, message, self.handler.root ) return # ensure that two player games have two different players if t == "Two Player" and p[0] == p[1] : title = "Error: Game Addtion" message = "No game added.\nError: Use 'Play Self' instead of 'Two Player' for an agent to play itself." wgt.ShowError( title, message, self.handler.root ) return # make the new game b = None if box_needed : b = BlueBox ( self.gamesScrollFrame.interior ) b.grid (sticky=tk.W) self.gamesScrollFrame.set_scrollregion() # update the scroll bar new_game = GameGUIData ( t, n, p, b ) if box_needed : new_game.gui_box.delButton.command = partial ( self.deleteSingleGame, new_game ) if self.dummyGameLabel is not None: self.dummyGameLabel.destroy() self.dummyGameLabel = tk.Label(self.gamesScrollFrame.interior, bg = "white", text = "\n\n") self.dummyGameLabel.grid(sticky=tk.W) self.gamesScrollFrame.set_scrollregion(vertical_buff=300) self.my_games.append ( new_game ) self.parent.update_idletasks() return
def __init__(self, handler, parent): self.parent = parent self.handler = handler ## make GameLog display frame self.log = [] self.cur_log = None self.gLFrame = tkinter.Frame(self.parent, highlightthickness=F_BORDER, highlightbackground="black") self.gLFrame.grid(column=0, row=0, columnspan=3, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N, padx=5) self.gameLog = tkinter.StringVar() self.gameLog.set("Game Log") self.gameLogLabel = tkinter.Label(self.gLFrame, textvar=self.gameLog, fg = FL_TEXT_COLOR, \ bg=FL_COLOR, borderwidth=FL_BD, relief=FL_STYLE, font=FL_FONT) self.gameLogLabel.grid(column=0, row=0) self.gameLogLabel.pack(side=tkinter.TOP, fill=tkinter.X) self.gLFrame.columnconfigure(0, weight=1) self.logTextFrame = wgt.ScrollableFrame(self.gLFrame) self.logTextFrame.canvas.config(height=450) self.gLFrame.columnconfigure(0, weight=1) self.logTextFrame.pack(fill="both") ## make totals display frame t_width = 475 if platform != "win32" else 600 t_height = 450 self.tFrame_outer = tkinter.Frame(self.parent, highlightthickness=F_BORDER, highlightbackground="black") self.tFrame_outer.config(bg="white") self.tFrame = wgt.ScrollableFrame(self.tFrame_outer) self.tFrame.canvas.config(bg="white", width=t_width, height=t_height) self.tFrame.set_scrollregion(vertical_buff=1000) #self.tFrame = tkinter.Frame(self.parent, highlightthickness = F_BORDER, highlightbackground="black") self.tFrame_outer.grid(column=3, row=0, columnspan=3, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N) self.totals = tkinter.StringVar() self.totals.set("Totals") self.totalsLabel = tkinter.Label(self.tFrame_outer, textvar=self.totals, fg = FL_TEXT_COLOR, \ bg=FL_COLOR, borderwidth=FL_BD, relief=FL_STYLE, font=FL_FONT, width=WIDTH) self.totalsLabel.pack(side=tkinter.TOP, fill=tkinter.X) self.tFrame.columnconfigure(3, weight=1) self.totalsStrVar = tkinter.StringVar() self.totalsTextLabel = tkinter.Label(self.tFrame.interior, textvar=self.totalsStrVar, fg="black", \ bg="white", font=("Courier", 15),\ height=HEIGHT,anchor=tkinter.W) self.totalsTextLabel.pack(side=tkinter.TOP, fill=tkinter.X) self.tFrame.columnconfigure(0, weight=1) self.totalsLabel.pack(side=tkinter.TOP, fill=tkinter.X) self.tFrame.pack() # update the totals areanow that the widgets are set #self.setScoreRecord ( "Totals stuff here" ) v_buf = (int(len(self.handler.game.players) / 24) + 1 if len(self.handler.game.players) % 24 > 0 else 0) self.totalsTextLabel.config(height=HEIGHT * v_buf, anchor=tkinter.N) self.tFrame.set_scrollregion(vertical_buff=HEIGHT * v_buf) #1000* ## make time display frame self.timeHeaderFrame = tkinter.Frame(self.parent, highlightthickness=F_BORDER, highlightbackground="black") self.timeHeaderFrame.grid(columnspan=6, column=0, row=1, sticky=tkinter.W+tkinter.E+tkinter.N, \ padx = 5, pady = 5) self.timeInfo = tkinter.StringVar() self.timeInfo.set("Time") self.timeInfoLabel = tkinter.Label(self.timeHeaderFrame, textvar = self.timeInfo, fg = FL_TEXT_COLOR,\ bg=FL_COLOR, borderwidth=FL_BD, relief=FL_STYLE, font=FL_FONT) self.timeInfoLabel.grid(column=2, row=2) self.timeInfoLabel.pack(side=tkinter.TOP, fill=tkinter.X) self.timeHeaderFrame.columnconfigure(0, weight=1) self.timeLabel = wgt.StopWatch(self.timeHeaderFrame) self.timeLabel.label.config(font=("Courier", 50, "bold")) self.timeLabel.pack(side=tkinter.TOP, fill=tkinter.X, padx=2) self.timeHeaderFrame.columnconfigure(0, weight=1) ## Make control buttons self.buttonFrame = tkinter.Frame(self.parent) self.buttonFrame.grid(column=6, row=0, rowspan=2, sticky=tkinter.N + tkinter.S) self.buttonText = tkinter.StringVar() font = ("Times New Roman", 24) self.UIbutton = wgt.ColoredButton(self.buttonFrame, text="Show Board", command=self.UIbuttonPressed) self.UIbutton.config(bg=self.handler.blue, fg='white', font=font, width=12, pady=3) self.UIbutton.grid() self.pauseButton = wgt.ColoredButton(self.buttonFrame, command=self.handler.pausePressed) self.pauseButton.config(textvar=self.handler.pauseVar) self.pauseButton.config(bg=self.handler.blue, fg='white', font=font, width=12, pady=3) self.pauseButton.grid(row=1) self.paused = True self.stepButton = wgt.ColoredButton(self.buttonFrame, text="Step", command=self.handler.stepPressed) self.stepButton.config(bg=self.handler.blue, fg='white', font=font, width=12, pady=3) self.stepButton.grid(row=2) self.statsButton = wgt.ColoredButton(self.buttonFrame, command=self.handler.statsPressed) self.statsButton.config(textvar=self.handler.statsText) self.statsButton.config(bg=self.handler.blue, fg='white', font=font, width=12, pady=3) self.statsButton.grid(row=3) self.stats = False self.killButton = wgt.ColoredButton(self.buttonFrame, text="Kill Game", command=self.handler.killPressed, backgroundcolor='red') self.killButton.config(bg='red', fg='white', font=font, width=12, pady=3) self.killButton.grid(row=4) self.restartButton = wgt.ColoredButton( self.buttonFrame, text="Restart All", command=self.handler.restartPressed, backgroundcolor='red') self.restartButton.config(bg='red', fg='white', font=font, width=12, pady=3) self.restartButton.grid(row=5) self.settingsButton = wgt.ColoredButton( self.buttonFrame, text="Settings", command=self.handler.settingsPressed, backgroundcolor='red') self.settingsButton.config(bg='red', fg='white', font=font, width=12, pady=3) self.settingsButton.grid(row=6) # make buttons space out a bit for i in range(7): self.buttonFrame.rowconfigure(i, weight=1) self.dummyStatLabel = None
def createFrames(self): # make game board self.boardFrame = tkinter.Frame(self.parent) self.boardFrame.config(bd=1, bg='black') self.boardIcons = [] # game board is based on a 10*10 grid of tiles # access by self.boardIcons[y][x] # custom order to make things render nice for y in range(10): tmp = [] for x in range(10): button = BoardButton(self.boardFrame, self, x, y) tmp.append(button) self.boardIcons.append(tmp) self.boardFrame.grid(column=1, row=0) # test board drawing # self.randomBoard() # make player displays self.playerInfoFrame = tkinter.Frame(self.parent, relief=tkinter.GROOVE, borderwidth=2) # set up spacing for player names for i in (0, 4): self.playerInfoFrame.rowconfigure(i, weight=1) for i in (1, 2, 3): self.playerInfoFrame.rowconfigure(i, weight=0) # make tkinter variables with default values (should be overwritten before display) self.p1Name = tkinter.StringVar() self.p1Name.set("Player 1") self.p1Food = tkinter.IntVar() self.p1Food.set(0) self.p2Name = tkinter.StringVar() self.p2Name.set("Player 2") self.p2Food = tkinter.IntVar() self.p2Food.set(0) # make labels Wraplength = 1 causes text to be displayed vertically font = ("Times New Roman", 16) self.p1Label = tkinter.Label(self.playerInfoFrame) self.p1Label.config(textvar=self.p1Name, wraplength=1, font=font, fg='BLUE') self.p1Label.config(height=11) self.p1Label.grid(column=0, row=0, sticky=tkinter.N + tkinter.S) self.foodLabel = tkinter.Label(self.playerInfoFrame) self.foodLabel.config(text="Food", fg="BLACK", font=font) self.foodLabel.grid(column=0, row=1) self.p1FoodLabel = tkinter.Label(self.playerInfoFrame) self.p1FoodLabel.config(textvar=self.p1Food, font=font, fg='BLUE', width=2) self.p1FoodLabel.grid(column=0, row=2) self.p2FoodLabel = tkinter.Label(self.playerInfoFrame) self.p2FoodLabel.config(textvar=self.p2Food, font=font, fg='RED', width=2) self.p2FoodLabel.grid(column=0, row=3) self.p2Label = tkinter.Label(self.playerInfoFrame) self.p2Label.config(textvar=self.p2Name, wraplength=1, font=font, fg='RED') self.p2Label.config(height=12) self.p2Label.grid(column=0, row=4, sticky=tkinter.N + tkinter.S) # set weights so player labels are centered properly self.playerInfoFrame.rowconfigure(0, weight=1) self.playerInfoFrame.rowconfigure(3, weight=1) self.playerInfoFrame.grid(column=0, row=0, sticky=tkinter.N + tkinter.S) self.parent.rowconfigure(0, weight=1) # Make message pane font = ("Times New Roman", 16) self.messageFrame = tkinter.Frame(self.parent, bg="white", relief=tkinter.RIDGE, bd=2) self.messageText = tkinter.StringVar() self.messageText.set("Please Win") self.messageLabel = tkinter.Label(self.messageFrame, textvar=self.messageText, bg="white", font=font) self.messageLabel.grid() self.messageFrame.grid(column=1, row=1, sticky=tkinter.E + tkinter.W) self.messageFrame.columnconfigure(0, weight=1) # Make control buttons font = ("Times New Roman", 24) self.buttonFrame = tkinter.Frame(self.parent) self.buttonFrame.grid(column=2, row=0, rowspan=2, sticky=tkinter.N + tkinter.S) self.UIbutton = wgt.ColoredButton(self.buttonFrame, text="Hide Board", command=self.UIbuttonPressed, backgroundcolor=self.handler.blue) self.UIbutton.config(bg=self.handler.blue, fg='white', font=font, width=12, pady=3) self.UIbutton.grid() self.endTurnButton = wgt.ColoredButton(self.buttonFrame, text="End Turn", command=self.endTurnPressed) self.endTurnButton.config(bg=self.handler.blue, fg='white', font=font, width=12, pady=3) self.endTurnButton.grid(row=1) self.pauseButton = wgt.ColoredButton(self.buttonFrame, command=self.handler.pausePressed, backgroundcolor=self.handler.blue) self.pauseButton.config(textvar=self.handler.pauseVar) self.pauseButton.config(bg=self.handler.blue, fg='white', font=font, width=12, pady=3) self.pauseButton.grid(row=2) self.paused = True self.stepButton = wgt.ColoredButton(self.buttonFrame, text="Step", command=self.handler.stepPressed, backgroundcolor=self.handler.blue) self.stepButton.config(bg=self.handler.blue, fg='white', font=font, width=12, pady=3) self.stepButton.grid(row=3) self.statsButton = wgt.ColoredButton(self.buttonFrame, command=self.handler.statsPressed) self.statsButton.config(textvar=self.handler.statsText) self.statsButton.config(bg=self.handler.blue, fg='white', font=font, width=12, pady=3) self.statsButton.grid(row=4) self.stats = False self.killButton = wgt.ColoredButton(self.buttonFrame, text="Kill Game", command=self.handler.killPressed, backgroundcolor='red') self.killButton.config(bg='red', fg='white', font=font, width=12, pady=3) self.killButton.grid(row=5) self.restartButton = wgt.ColoredButton( self.buttonFrame, text="Restart All", command=self.handler.restartPressed, backgroundcolor='red') self.restartButton.config(bg='red', fg='white', font=font, width=12, pady=3) self.restartButton.grid(row=6) self.settingsButton = wgt.ColoredButton( self.buttonFrame, text="Settings", command=self.handler.settingsPressed, backgroundcolor='red') self.settingsButton.config(bg='red', fg='white', font=font, width=12, pady=3) self.settingsButton.grid(row=7) self.undoButton = wgt.ColoredButton(self.buttonFrame, text="Undo", command=self.undoPressed, backgroundcolor=self.handler.blue) self.undoButton.config(bg=self.handler.blue, fg='white', font=font, width=12, pady=3) self.undoButton.grid(row=8) # make buttons space out a bit for i in range(9): self.buttonFrame.rowconfigure(i, weight=1)