Apr-14-2019, 10:02 PM
I am in the process of writing an Othello (reversi) game for my mother. It's nearly done, but to polish it off, I want to add a help section. Currently, I've implemented this functionality using tkinter.messagebox.showinfo() but I want a more comprehensive help section, I want it to look nicer, and I don't want that annoying sound to play when the info box appears on the screen.
This is a code sample resembling what I tried before resorting to messageboxes:
This is a code sample resembling what I tried before resorting to messageboxes:
from tkinter import * from tkinter import scrolledtext from tkinter import messagebox # This still gets used elsewhere, even if I succeed in creating a custom help window. import time # This also gets used elsewhere. # Globals containing the help texts in triple quoted strings: gameRules = """Game Rules A comprehensive explanation of the gamerules goes here. """ applicationHelp = """Application help An explanation of how the app works goes here. """ # For encapsulation purposes, the application goes in here: # I don't inherit from Frame or anything. You'll see. It works. class OthelloGame: bgAndBoardColor = "#41A123" def __init__ (self, master): self.master = master self.master.geometry("697x745+128+128") self.master.title("tkOthello") # The important stuff: I put other stuff in this toolbar, but I'm trying to limit the code to stuff that's relevant to this post. self.toolbar = Menu(self.master) self.master.config(menu = self.toolbar) self.helpMenu = Menu(self.toolbar) self.toolbar.add_cascade(label = "Help", menu= self.helpMenu) self.helpMenu.add_command(label = "Gamerules", command = self.showGameRules) self.helpMenu.add_command(label = "Application Help", command = self.showApplicationHelp) # Other configuration code like setting up the gameboard goes here, but it's not the subject of this post. def showGameRules (self): global gameRules self.showHelp(gameRules) def showApplicationHelp (self): global applicationHelp self.showHelp(applicationHelp) def showHelp (self, helpText): # When the main application is closed before the help window, it causes an error. # The application is being closed anyway, so it's not a big problem. My main concern # is that it would be alarming to the user to see the tracebacks appear in the console # window, which I don't know how to hide. Any help on that would be appreciated as well. helpWindow = Tk() helpWindow.geometry("512x512+256+256") helpWindow.title("tkOthello " + helpText.split("\n")[0]) helpWindow_bgFrame = Frame(helpWindow, bg = self.bgAndBoardColor) # This is as far as I got before I noticed the problem I described above, but I did add the obligatory helpWindow.mainloop() seen below. helpWindow.mainloop() if __name__ == __main__: root = Tk() myGame = OthelloGame(root) root.mainloop()Incidentally, How do I get this awesome code coloring in IDLE or pycharm (A very good IDE by the way. I wish I had it sooner.)