def _create_widgets(self): if self.isapp: self.msgPanel = MsgPanel(self, [ "Instruction:\n", " - Click on any of the pieces next to the space and that\n", " piece will slide over the space.\n", " - Continue this until the pieces are arranged in\n", " numerical order. Refer 4x4 result below.\n\n", "The end result in 4x4 puzzle:\n", " 1 2 3 4\n", "12 13 14 5\n", "11 15 6\n", "10 9 8 7" ]) self.seeDismissPanel = SeeDismissPanel(self) self._create_demo_panel()
def _create_widgets(self): if self.isapp: MsgPanel(self, [ "Drag the 'sash' between the two scrolled windows ", "to resize them." ]) SeeDismissPanel(self) self._create_demo_panel()
def _create_widgets(self): if self.isapp: MsgPanel(self, ["This window displays a canvas widget containing ", "a simple 2-dimensional plot. You can doctor the ", "data by dragging any of the points with mouse button 1."]) SeeDismissPanel(self) self._create_demo_panel()
def _create_widgets(self): if self.isapp: MsgPanel(self, [ "This demonstration shows off a nested set of themed paned ", "windows. Their sizes can be changed by grabbing the area ", "between each contained pane and dragging the divider." ]) SeeDismissPanel(self) self._create_demo_panel()
def _create_widgets(self): if self.isapp: MsgPanel(self, [ "An arrow and a vertical scale are displayed below. ", "If you click or drag mouse button 1 in the scale, you ", "can change the length of the arrow." ]) SeeDismissPanel(self) self._create_demo_panel()
def _create_widgets(self): if self.isapp: MsgPanel(self, ["Three different spin-boxes are displayed below. ", "The first, which is 'read only', displays a different ", "background colour.\n", "Select a value using the up/down arrowhead keys ", "or keyboard up/down arrow keys."]) SeeDismissPanel(self) self._create_demo_panel()
def _create_widgets(self): if self.isapp: MsgPanel(self, ["Three different spin-boxes are displayed below. ", "The first is fully editable, pressing 'Return' adds ", "the entered text to the list. The second is disabled. ", "The third is a pre-defined, non-editable list.\n", "Select a value using the up/down arrowhead keys or ", "keyboard up/down arrow keys."]) SeeDismissPanel(self) self._create_demo_panel()
def _create_widgets(self): if self.isapp: MsgPanel(self, ["One of the new Tk themed widgets is a tree widget, which allows ", "the user to browse a hierarchical data-set such as a file system. ", "The tree widget not only allows for the tree part itself, but it ", "also supports an arbitrary number of additional columns which can ", "show additional data (in this case, the size of the files found ", "on your file system). You can also change the width of the columns ", "by dragging the boundary between them."]) SeeDismissPanel(self) self._create_demo_panel()
def _create_widgets(self): if self.isapp: MsgPanel(self, [ "One of the new Ttk widgets is a tree widget ", "which can be configured to display multiple columns of data without ", "displaying the tree itself. This is a simple way to build a listbox that has multiple ", "columns.\n\n", "Click a column heading to re-sort the data. ", "Drag a column boundary to resize a column."]) SeeDismissPanel(self) self._create_demo_panel()
def _create_widgets(self): if self.isapp: MsgPanel(self, [ "Below are two progress bars. The top one is a \u201Cdeterminate\u201D ", "progress bar, which is used for showing how far through a defined task ", "the program has got. The bottom one is an \u201Cindeterminate\u201D ", "progress bar, which is used to show that the program is busy but does ", "not know how long for. Both are run here in self-animated mode, which ", "can be turned on and off using the buttons underneath." ]) SeeDismissPanel(self) self._create_demo_panel()
def _create_widgets(self): if self.isapp: MsgPanel(self, [ "This demonstration shows how Tkinter can be used to carry out animations ", "that are linked to simulations of physical systems. In the left canvas ", "is a graphical representation of the physical system itself, a simple ", "pendulum, and in the right canvas is a graph of the phase space of the ", "system, which is a plot of the angle (relative to the vertical) against ", "the angular velocity. The pendulum bob may be repositioned by clicking ", "and dragging anywhere on the left canvas." ]) SeeDismissPanel(self) self._create_demo_panel()
def _create_widgets(self): if self.isapp: MsgPanel(self, [ "This widget allows you to experiment with different ", "widths and arrowhead shapes for lines in canvases. ", "To change the line width or the shape of the arrowhead, ", "drag any of the three boxes attached to the oversized ", "arrow. The arrows on the right give examples at normal ", "scale. The text at the bottom shows the configuration ", "options as you'd enter them for a canvas line item." ]) SeeDismissPanel(self) self._create_demo_panel()
def _create_widgets(self): if self.isapp: MsgPanel(self, [ "Three groups of radiobuttons are displayed below. If you click on a button then ", "the button will become selected exclusively among all the buttons in its group. ", "A control variable is associated with each group to indicate which of the group's ", "buttons is selected.\n\n", "Selecting a Point Size or Color changes the associated Labelframe text.\n\n", "Selecting an Alignment repositions the graphic with respect ", "to the label i.e. 'Bottom' puts the graphic 'below' the label." ]) SeeDismissPanel(self) self._create_demo_panel()
def _create_widgets(self): if self.isapp: MsgPanel(self, [ "Ttk is the new Tk themed widget set. This is a Ttk themed label, ", "and below are three groups of Ttk widgets in Ttk labelframes.\n\n", "The first group are all buttons that set the current application ", "theme when pressed. Note the message box does not change as it uses ", "a standard tkinter Label to hold the message.\n", "The second group contains three sets of checkbuttons, ", "with a separator widget between the sets. ", "Note that the 'Enabled' button controls whether or not all the other ", "buttons are in the disabled state.\n", "The third group has a collection of linked radiobuttons." ]) SeeDismissPanel(self) self._create_demo_panel() self.allBtns = self.ttkbut + self.cbs[1:] + self.rb
def _create_widgets(self): if self.isapp: MsgPanel(self, ["This is a demonstration of how to do ", "a toolbar that is styled correctly and which ", "can be torn off. The buttons are configured ", "to be 'toolbar style' buttons by ", "telling them that they are to use the Toolbutton ", "style. At the left end of the toolbar is a ", "simple marker, on mouse over, the cursor changes to a ", "movement icon; drag that away from the ", "toolbar to tear off the whole toolbar into a ", "separate toplevel widget. When the dragged-off ", "toolbar is no longer needed, just close it like ", "any normal toplevel and it will reattach to the ", "window it was torn from."]) SeeDismissPanel(self) self._create_demo_panel()
class PuzzleDemo(Frame): def __init__(self, puzzleTiles, puzzleSize): Frame.__init__(self, name='puzzledemo') self.puzzleTiles = puzzleTiles self.puzzleSize = puzzleSize self.pack(expand=Y, fill=BOTH) self.master.title('N-Puzzle GUI') self.isapp = True self.tileButtonList = [None] * puzzleSize**2 self.tilePosArray = [] self.posFactor = 1 / self.puzzleSize self.msgPanel = None self.seeDismissPanel = None self._create_widgets() def _create_widgets(self): if self.isapp: self.msgPanel = MsgPanel(self, [ "Instruction:\n", " - Click on any of the pieces next to the space and that\n", " piece will slide over the space.\n", " - Continue this until the pieces are arranged in\n", " numerical order. Refer 4x4 result below.\n\n", "The end result in 4x4 puzzle:\n", " 1 2 3 4\n", "12 13 14 5\n", "11 15 6\n", "10 9 8 7" ]) self.seeDismissPanel = SeeDismissPanel(self) self._create_demo_panel() def _create_demo_panel(self): bgColor = 'gray80' # colour for panel background and empty space # if width and height are not specifically set buttons are positioned # in a 0 size window and do not show up demoPanel = Frame(self, borderwidth=2, relief=SUNKEN, background=bgColor, width=520, height=520) demoPanel.pack(side=TOP, pady=1, padx=1) # buttons are placed relative to the top, left corner of demoPanel # with relations expressed as a value between 0.0 and 1.0 # top, left corner = (x,y) = (0,0) # bottom, right corner = (x,y) = (1,1) self.xypos = {} for i in range(self.puzzleSize): for j in range(self.puzzleSize): self.tilePosArray.append(None) for i in range(self.puzzleSize): for j in range(self.puzzleSize): num = self.puzzleTiles[i][j] self.tilePosArray[num] = (i, j) if (num == 0): self.xypos['space'] = (j * self.posFactor, i * self.posFactor) else: self.xypos[num] = (j * self.posFactor, i * self.posFactor) b = ttk.Button(text=num, style='Puzzle.TButton') self.tileButtonList[num] = b b['command'] = lambda b=b: self.puzzle_switch(b) b.place(in_=demoPanel, relx=self.xypos[num][0], rely=self.xypos[num][1], relwidth=self.posFactor, relheight=self.posFactor) # set button background to demoPanel background ttk.Style().configure('Puzzle.TButton', background=bgColor) def puzzle_switch(self, button): num = button['text'] sx = self.xypos['space'][0] # position of 'space' sy = self.xypos['space'][1] x = self.xypos[num][0] # position of selected button y = self.xypos[num][1] # is the selected button next to the space? if (sy - .01 <= y <= sy + .01 and sx - self.posFactor - .01 <= x <= sx + self.posFactor + .01 or sx - .01 <= x <= sx + .01 and sy - self.posFactor - .01 <= y <= sy + self.posFactor + .01): # swap button with space self.xypos['space'], self.xypos[num] = self.xypos[num], self.xypos[ 'space'] # re-position button button.place(relx=self.xypos[num][0], rely=self.xypos[num][1]) tmp = self.tilePosArray[num] self.tilePosArray[num] = self.tilePosArray[0] self.tilePosArray[0] = tmp else: print("Invalid move!") def getTileButtons(self): return (self.tileButtonList) def getEmptyTilePos(self): return (self.tilePosArray[0]) def terminate_gui(self): self.seeDismissPanel.winfo_toplevel().destroy()
def _create_widgets(self): if self.isapp: SeeDismissPanel(self) self._create_demo_panel()