tkintertoy module

class tt.Window(master=None, extra=False, **tkparms)

Bases: object

An easy GUI creator intended for novice Python programmers, built upon Tkinter.

This will create a Tk window with a contents dictionary. The programmer adds “ttWidgets” to the window using the add* methods where the programmer assigns a string tag to a widget. Almost all ttk and most tk widgets are included, with some useful combined widgets. Most tk/ttk widgets are placed in a frame which can act as a prompt of the ttWidget to the user. The programmer places the ttWidgets using the plot method which is a synonym for the tkinter grid geometry manager. Contents of the widget are assigned and retrieved by using the tags to the set and get methods. This greatly simplifies working with GUIs. Also, all ttWidgets are bundled into the window object so individual ttWidgets do not need to be passed to other routines, which simplifies interfaces. However, more experienced Python programmers can access the tk/ttk widget and frames directly and take advantage of the full power of Tk and ttk.

In the below methods, not all the possible keyword arguments are listed, only the most common ones were selected. The Tkinter documentation lists all for every widget. However, tk control variables should NOT be used since they might interfere on how the set and get methods work. Default values are shown in brackets [].

In some themes, certain parameters (like background) will not work in ttk widgets. For this reason, all ttk widgets have an option to use the older tk widget by setting the usetk argument to True.

Due to problems with textvariable in nested frames with ttk, the textvariable option is not used in any of the below methods.

After creating a Window object, the master attribute will either be a Tk Frame or a Toplevel window.

Here is a summary of the methods:
add* - add a new ttWidget to a window get* - get the contents or an part of the ttWidget set* - change the contents or an attribute of the widget pop* - pop-up a dialog window
Parameters:
  • master (tk.Toplevel or tk.Frame) – The containing window
  • extra (bool) – True if this is an extra window apart from the main
Keyword Arguments:
 
  • borderwidth (int) – Width of border (pixels)
  • height (int) – Height of frame (pixels)
  • padding (int) – Spaces between frame and widgets (pixels)
  • relief (str) – [‘flat’],’raised’,’sunken’,’groove’, or ‘ridge’
  • style (ttk.Style) – Style used for ttk.Frame or ttk.LabelFrame
  • width (int) – Width of frame (pixels)

Included in the installation is a copy of John Shipman’s “Tkinter 8.5 reference: a GUI for Python” from New Mexico Tech, which is the best printed version known to the author. Unfortunately, Dr. Shipman has passed away and it is getting harder to find. When the code references Tkinter documentation it is referring to Dr. Shipman’s work.

VERSION = '1.60'
__contains__(tag)

Checks if widget tag is in window.

Called using the in operator.

Returns:True if ‘tag’ is in window
__len__()

Return number of widgets in window.

Called using the builtin len() function.

Returns:Number of widgets in window
__repr__()

Display content dictionary structure, useful for debugging.

Called using the builtin repr() function.

Returns:String of self.master, self.content
addButton(tag, prompt='', cmd=[], space=3, orient='horizontal', usetk=False, **tkparms)

Create a ttButtonbox, defaults to Ok - Cancel.

This widget is where one would place most of the command buttons for a GUI, usually at the bottom of the window. Clicking on a button will execute a method usually called a callback. Two basic ones are included; Ok and Cancel. The keyword arguments will apply to EVERY button.

Parameters:
  • tag (str) – Reference to widget
  • prompt (str) – Text of frame label
  • cmd (list) – (label:str, callback:function) for each button
  • space (int) – space (pixels) between buttons
  • orient (str) – [‘horizontal’] or ‘vertical’
  • usetk (bool) – Use tk instead of ttk
Keyword Arguments:
 
  • compound (str) – Display both image and text, see ttk docs
  • image (tk.PhotoImage) – GIF/PNG image to display
  • style (ttk.Style) – Style to use for checkboxes
  • width (int) – Width of label (chars)
Returns:

list of ttk/tk.Buttons

addCanvas(tag, prompt='', scrollbars=False, **tkparms)

Create a ttCanvas window.

The tk.Canvas is another extremely powerful widget that displays graphics. Again, read the Tkinter documentation to discover all the features of this widget.

Parameters:
  • tag (str) – Reference to widget
  • prompt (str) – Text of frame label
  • scrollbars (bool) – True if scrollbars are added
Keyword Arguments:
 
  • width (int) – Width of window (pixels)
  • height (int) – Height of window (pixels)
  • background (str) – Background color
  • closeenough (float) – Mouse threshold
  • confine (bool) – Canvas cannot be scrolled ourside scrolling region
  • cursor (str) – Mouse cursor
  • scrollregion (list of int) – w, n, e, s bondaries of scrolling region
Returns:

tk.Canvas

addCheck(tag, prompt='', alist=[], orient='horizontal', usetk=False, **tkparms)

Create a ttCheckbutton box.

Checkboxes are used to collect options from the user, similar to a listbox. Checkboxes might be better for short titled options because they don’t take up as much screen space. The keyword arguments will apply to EVERY checkbutton. Get/set uses list of str.

Parameters:
  • tag (str) – Reference to widget
  • prompt (str) – Text of frame label
  • alist (list) – (str1, str2, …)
  • orient (str) – [‘horizontal’] or ‘vertical’
  • usetk (bool) – Use tk instead of ttk
Keyword Arguments:
 
  • command (callback) – Function to execute when boxes are toggled
  • compound (str) – Display both image and text, see ttk docs
  • image (tk.PhotoImage) – GIF image to display
  • style (ttk.Style) – Style to use for checkboxes
  • width (int) – Width of max checkbox label (chars), negative sets minimum
Returns:

list of ttk/tk.Checkbuttons

addChooseDir(tag, prompt='', width=20, **tkparms)

Create a ttChoosedirbox which is a directory entry with a browse button.

This has all the widgets needed to select a directory. When the user clicks on the Browse button, a standard Choose Directory dialog box pops up. There are many tkparms that are useful for limiting choices, see the Tkinter documentation. Get/set uses str. Normally, this would be use in a dialog. For a menu command use popChooseDir. Width is a necessary option since tkparms is for the askopenfilename widget.

Parameters:
  • tag (str) – Reference to widget
  • prompt (str) – Text of frame label
  • width (int) – Width of entry widget
Keyword Arguments:
 
  • initialdir (str) – Initial directory (space, ‘ ‘ remembers last directory)
  • title (str) – Pop-up window’s title
Returns:

list of ttk/tk.Entry and ttk/tk.Button

addCollector(tag, columns, widgets, prompt='', **tkparms)

Create a ttCollectorbox which is based on a treeview that collects contents of other widgets.

This collection of widgets allows the programmer to collect the contents of other widgets into a row. The user can add or delete rows as they wish using the included buttons. Get/set uses list of str. There is no tk version.

Parameters:
  • tag (str) – Reference to widget
  • columns (list) – (Column headers, width (pixels))
  • widgets (list) – (Tags) for simple or (window, tag) for embedded widgets
  • prompt (str) – Text of frame label
Keyword Arguments:
 
  • height (int) – Height of widget
  • padding (int) – Spaces around values
  • style (ttk.Style) – Style used for ttk.Treeview
Returns:

list of ttk.Treeview and two ttk.Buttons

addCombo(tag, prompt='', values=None, **tkparms)

Create a ttCombobox.

Comboboxes combine features of Entry and Listbox into a single widget. The user can select one option out of the list or even type in their own. It is better than lists for a large number of options. Get/set uses str or list of str. There is no tk version.

Parameters:
  • tag (str) – Reference to widget
  • prompt (str) – Text of frame label
  • values (list) – (str1, str2, …)
Keyword Arguments:
 
  • height (int) – Maximum number of rows in dropdown [10]
  • justify (str) – Justification of text ([‘left’], ‘right’, ‘center’)
  • postcommand (callback) – Function to call when user clicks on downarrow
  • style (ttk.Style) – Style to use for widget
  • width (int) – Width of label (chars) [20]
Returns:

ttk.Combobox

addEntry(tag, prompt='', usetk=False, **tkparms)

Create an ttEntry.

Entries are the widget to get string input from the user. Get/set uses str.

Parameters:
  • tag (str) – Reference to widget
  • prompt (str) – Text of frame label
  • usetk (bool) – Use tk instead of ttk
Keyword Arguments:
 
  • justify (str) – Justification of text (‘left’ [def], ‘right’, ‘center’)
  • show (str) – Char to display instead of actual text
  • style (ttk.Style) – Style to use for widget
  • width (int) – Width of label [20] (chars)
Returns:

ttk/tk.Entry

addFrame(tag, prompt='', usetk=False, **tkparms)

Create a labeled or unlabeled frame container.

This allows the programmer to group widgets into a new window. The window can have either a title or a relief style, but not both.

Parameters:
  • tag (str) – Reference to container
  • prompt (str) – Text of frame label
  • usetk (bool) – Use tk instead of ttk
Keyword Arguments:
 
  • boarderwidth (int) – width of border (for relief styles only)
  • height (int) – Height of frame (pixels)
  • padding (int) – Spaces between frame and widgets (pixels)
  • relief (str) – ‘flat’,’raised’,’sunken’,’groove’, or ‘ridge’
  • style (int) – Style used for ttk.Frame or ttk.LabelFrame
  • width (int) – Width of frame (pixels)
Returns:

tt.Window

addLabel(tag, prompt='', effects='', usetk=False, **tkpamrs)

Create a ttLabel.

Labels are used to display simple messages to the user. An effects parameter is included for the simplest font types but this will override the font keyword argument. Get/set uses str.

Parameters:
  • tag (str) – Reference to widget
  • prompt (str) – Text of frame label
  • effects (str) – ‘bold’ and/or ‘italic’
  • usetk (bool) – Use tk instead of ttk
Keyword Arguments:
 
  • anchor (str) – Position in widget; [‘c’], ‘w’, ‘e’)
  • background (str) – Background color
  • compound (str) – Display both image and text, see ttk docs
  • font (tkfont.Font) – Font for label
  • foreground (str) – Text color
  • image (tk.PhotoImage) – GIF image to display
  • justify (str) – Justification of text; [‘left’], ‘right’, ‘center’
  • padding (list) – Spacing (left, top, right, bottom) around widget (pixels)
  • text (str) – The text inside the widget
  • width (int) – Width of label (chars)
  • wraplength (int) – Character position to word wrap
Returns:

ttk/tk.Label

addLedger(tag, columns, prompt='', **tkparms)

Create a ttLedger which is based on a treeview that displays a simple list with column headers.

This widget allows a nice display of data in columns. It is a simplified version of the Collector widget. Due to a bug in ttk, sideways scrolling does not work correctly. If you need sideways scrolling use the Text widget. Get/set uses list of str. There is no tk version.

Parameters:
  • tag (str) – Reference to widget
  • columns (list) – (Column headers, width (pixels))
  • prompt (str) – Text of frame label
Keyword Arguments:
 
  • height (int) – Height of widget
  • padding (int) – Spaces around values
  • selectmode (str) – [‘browse’] or ‘extended’
  • (ttk (style) – Style): Style used for ttk.Treeview
Returns:

ttk.Treeview

addLine(tag, **tkparms)

Create a horizontal or vertical ttLine across the entire frame.

Lines are useful for visually separating areas of widgets. They have no frame. There is no tk version. Be sure to use the sticky keyword when plotting or it will be a single dot.

Parameters:

tag (str) – Reference to widget

Keyword Arguments:
 
  • orient (str) – [‘horizontal’] or ‘vertical’
  • style (ttk.Style) – Style to use for line
Returns:

ttk.Separator

addList(tag, prompt='', alist=[], **tkparms)

Create a ttListbox.

Lists allow the user to select a series of options in a vertical list. It is best for long titled options but does take up some screen space. Since this is a Tk widget, there is no style keyword argument. Get/set uses list of str.

Parameters:
  • tag (str) – Reference to widget
  • prompt (str) – Text of frame label
  • alist (list) – (str1, str2, …)
Keyword Arguments:
 
  • background (str) – Background color
  • font (tkfont.Font) – Font for label
  • foreground (str) – Text color
  • height (int) – Height of listbox (chars) [10]
  • selectmode (str) – [‘browse’], ‘single’, ‘multiple’, or ‘extended’
  • width (int) – Width of label (chars) [20]
Returns:

tk.listbox

addMenu(tag, parent, items=None, **tkparms)

Add a tt.Menu

Menus are complex so read the Tkinter documentation carefully.

Parameters:
  • tag (str) – Reference to menu
  • parent (ttk.Menubutton or tk.Frame) – What menu is attached to
  • items (list) – (‘cascade’ or ‘checkbutton’ or ‘command’ or ‘radiobutton’ or ‘separator’, coptions) (see Tkinter Documentation)
Keyword Arguments:
 

Varies (dict) – see Tkinter documentation

Returns:

tk.Menu

addMenuButton(tag, usetk=False, **tkparms)

Add a ttMenubutton

A menubutton always stays on the screen and is what the user clicks on. A menu is attached to the menubutton. Menus are complex so read the Tkinter documentation carefully.

Parameters:tag (str) – Reference to menubutton
Keyword Arguments:
 Varies (dict) – see Tkinter documentation
Returns:ttk/tk.Menubutton
addMessage(tag, prompt, **tkparms)

Create a ttMessage which is like multiline label.

Messages are used to display multiline messages to the user. This is a tk widget so the list of options is extensive. This widget’s behavior is a little strange so you might prefer the Text or Label widgets. Get/set uses str.

Parameters:
  • tag (str) – Reference to widget
  • prompt (str) – Text of frame label
Keyword Arguments:
 
  • aspect (int) – Ratio of width to height
  • background (str) – Background color
  • borderwidth (int) – Width of border (pixels)
  • font (tkfont.Font) – Font for label
  • foreground (str) – Text color
  • justify (str) – Justification of text; [‘left’], ‘right’, ‘center’
  • padx (int) – Horizontal spaces to place around widget (pixels)
  • pady (int) – Vertical spaces to place around widget (pixels)
  • relief (str) – ‘flat’,’raised’,’sunken’,’groove’, or ‘ridge’
  • text (str) – The text inside the widget
  • width (int) – Width of message (pixels)
Returns:

tk.Message

addNotebook(tag, tabs, **tkparms)

Create a tabbed notebook container.

This allows the programmer to group similar pages into a series of new windows. The user selects the active window by clicking on the tab. Assignment allows the program to display a page tab, and return the currently selected page. There is no containing frame. Get/set uses int. There is no tk version.

Parameters:
  • tag (str) – Reference to container
  • tabs (list) – (Tab Titles), each page must be unique
Keyword Arguments:
 
  • height (int) – Height of frame (pixels)
  • padding (int) – Spaces between frame and widgets (pixels)
  • style (int) – Style used for ttk.Frame or ttk.LabelFrame
  • width (int) – Width of frame (pixels)
Returns:

list of tt.Windows

addOpen(tag, prompt='', width=20, **tkparms)

Create a ttOpenbox which is a file entry and a browse button.

This has all the widgets needed to open a file. When the user clicks on the Browse button, a standard Open dialog box pops up. There are many tkparms that are useful for limiting choices, see the Tkinter documentation. Get/set uses str. Normally, this widget would be in a dialog. For a menu command use popOpen. Width is a necessary option since tkparms is for the askopenfilename widget. If the programmer as an icon, they can replace the ‘Browse’ text.

Parameters:
  • tag (str) – Reference to widget
  • prompt (str) – Text of frame label
  • width (int) – Width of the entry widget
Keyword Arguments:
 
  • defaultextension (str) – extention added to filename (must strat with .)
  • filetypes (list) – entrys in file listing ((label1, pattern1), (…))
  • initialdir (str) – Initial directory (space, ‘ ‘ remembers last directory)
  • initialfile (str) – Default filename
  • title (str) – Pop-up window’s title
Returns:

list of ttk/tk.Entry and ttk/tk.Button

addOption(tag, prompt='', alist=[])

Create an ttOptionmenu.

Option menus allow the user to select one fixed option, similar to Radiobutton. However, option menu returns a tk.Menu and is more difficult to manipulate. There are no keyword arguments in tk.OptionMenu. Get/set uses str.

Parameters:
  • tag (str) – Reference to widget
  • prompt (str) – Text of frame label
  • alist (list) – (str1, str2, …)
Returns:

tk.OptionMenu

addPanes(tag, titles, usetk=False, **tkparms)

Create a multipaned window with user adjustable columns.

This is like a notebook but all the windows are visible and the widths are adjustable. There is no frame.

Parameters:
  • tag (str) – Reference to container
  • titles (list) – (titles) of all embedded windows
  • usetk (bool) – Use tk instead of ttk
Keyword Arguments:
 
  • height (int) – Height of frame (pixels)
  • orient (str) – [‘horizontal’] or ‘vertical’
  • padding (int) – Spaces between frame and widgets (pixels)
  • style (int) – Style used for ttk.Frame or ttk.LabelFrame
  • width (int) – Width of frame (pixels)
Returns:

list of tt.Windows

addProgress(tag, prompt='', **tkparms)

Create a ttProgressbar.

This indicates to the user how an action is progressing. The included method supports a determinate mode where the programmer tells the user exactly how far they have progressed. Ttk also supports a indeterminate mode where a rectangle bounces back a forth. See the Tkinter documentation. Get/set uses int. There is no tk version.

Parameters:
  • tag (str) – Reference to widget
  • prompt (str) – Text of frame label
Keyword Arguments:
 
  • maximum (int) – Maximum value [100]
  • mode (str) – [‘determinate’] or ‘indeterminate’
  • style (str) – Style to use for ttk.Progressbar
  • length (int) – Length of widget (pixels)
  • orient (str) – ‘horizontal’ or ‘vertical’
Returns:

ttk.Progressbar

addRadio(tag, prompt='', alist=[], orient='horizontal', usetk=False, **tkparms)

Create a ttRadiobutton box.

Radiobuttons allow the user to select only one option. If they change options, the previous option is unselected. This was the way old car radios worked hence its name. They are better for short titled options. The keyword arguments will apply to EVERY radiobutton. Get/set uses str.

Parameters:
  • tag (str) – Reference to widget
  • prompt (int) – Text of frame label
  • alist (list) – (str1, str2, …)
  • orient (str) – ‘horizontal’ or ‘vertical’
  • usetk (bool) – Use tk instead of ttk
Keyword Arguments:
 
  • command (callback) – Function to execute when boxes are toggled
  • compound (str) – Display both image and text, see ttk docs
  • image (tk.PhotoImage) – GIF image to display
  • style (ttk.Style) – Style to use for checkboxes
  • width (int) – Width of max label (chars), negative sets minimun
Returns:

list of ttk/tk.Radiobuttons

addSaveAs(tag, prompt='', width=20, **tkparms)

Create an ttSaveasbox which is a file entry with a browse button.

This has all the widgets needed to save a file. When the user clicks on the Browse button, a standard SaveAs dialog box pops up. If the user selects an existing file, it will pop up a overwrite confirmation box. There are many tkparms that are useful for limiting choices, see the Tkinter documentation. Get/set uses str. Normally, this widget would be in a dialog. For a menu command, use popSaveAs. Width is a necessary option since tkparms is for the asksaveasfilename widget.

Parameters:
  • tag (str) – Reference to widget
  • prompt (str) – Text of frame label
  • width (int) – Width of the entry widget
Keyword Arguments:
 
  • defaultextension (str) – extention added to filename (must strat with .)
  • filetypes (list) – entrys in file listing ((label1, pattern1), (…))
  • initialdir (str) – Initial directory (space, ‘ ‘ remembers last directory)
  • initialfile (str) – Default filename
  • title (str) – Pop-up window’s title
Returns:

list of ttk/tk.Entry and ttk/tk.Button

addScale(tag, parms, prompt='', width=4, usetk=False, **tkparms)

Create a ttScale which is an integer scale with entry box.

Scale allows the user to enter an integer value using a sliding scale. The user can also type in a value directly in the entry box. Get/set uses int. The tk widget has many more options

Parameters:
  • tag (str) – Reference to widget
  • parms (list) – Limits of scale (from, to)
  • prompt (str) – Text of frame label
  • width (int) – Width of entry widget (chars)
  • usetk (bool) – Use tk instead of ttk
Keyword Arguments:
 
  • command (callback) – Function to call when scale changes
  • length (int) – Length of scale (pixels) [100]
  • orient (str) – ‘horizontal’ or ‘vertical’
  • style (str) – Style to use for ttk.Scale
Returns:

list of ttk/tk.Scale and ttk/tk.Entry

addScrollbar(tag, widgetTag, orient='horizontal', usetk=False, **tkparms)

Add a ttScrollbar to a widget.

This is usually this is done automatically. There is no frame. In order to plot the programmer must get the widget frame and use the correct sticky option. It was included for completeness.

Parameters:
  • tag (str) – Reference to widget
  • widgetTag (str) – Tag of connected widget
  • orient (str) – [‘horizontal’] or ‘vertical’
Keyword Arguments:
 

style (ttk.Style) – Style used for ttk.Scrollbar

Returns:

ttk/tk.Scrollbar

addSizegrip(tag, **tkparms)

Add a ttSizegrip widget to the window.

This places a sizegrip in the bottom right corner of the window. It is not needed since most platforms add this automatically. The programmer must use the configurerow and configurecolumn options when plotting widgets for this to work correctly. There is no frame. It was included for completeness. There is no tk version.

Parameters:tag (str) – Reference to widget
Keyword Arguments:
 style (ttk.Style) – Style used for ttk.Sizegrip, mainly background
Returns:ttk.Sizegrip
addSpin(tag, parms, between=' ', prompt='', usetk=False, **tkparms)

Create a ttSpinbox.

Spinboxes allow the user to enter a series of integers. It is best used for items like dates, time, etc. The keyword arguments will apply to EVERY spinbox. Since this is a Tk widget, there is no style keyword argument. Get/set uses str.

Parameters:
  • tag (str) – Reference to widget
  • parms (list) – Parmeters for each spinbox ((width, from, to),…)
  • between (str) – Label between each box
  • prompt (str) – Text of frame label
  • usetk (bool) – Use tk instead of ttk
Keyword Arguments:
 
  • command (callback) – Function to call when arrows are clicked
  • style (ttk.Style) – Style to use for widget
  • justify (str) – Text justification; [‘left’], ‘right’, ‘center’
  • wrap (bool) – Arrow clicks wrap around
Returns:

list of ttk/tk.Spinboxes

addStyle(tag, **tkparms)

Add a ttk.Style to be used for other widgets.

This is the method for changing the appearance of ttk widgets. Styles are strictly defined strings so look at the Tkinter documentation.

Parameter:
tag (str): Reference to style, must follow ttk naming
Keyword Arguments:
 with widget, see Tkinter documentation (Varies) –
addText(tag, prompt='', **tkparms)

Create a ttText window.

The tk.Text widget is an extremely powerful widget that can do many things, other than just displaying text. It is almost a mini editor. The default method allow the programmer to add and delete text. Be sure to read the Tkinter documentation to discover all the features of this widget. Since this is a Tk widget, there is no style keyword argument. Get/set uses str.

Parameters:
  • tag (str) – Reference to widget
  • prompt (str) – Text of frame label
Keyword Arguments:
 
  • background (str) – Background color
  • font (tkfont.Font) – Text font
  • foreground (str) – Text color
  • wrap (str) – Wordwrap method; [‘char’], ‘word’, or ‘none’
  • width (int) – Width of window (chars)
  • height (int) – Height of window (chars)
Returns:

tk.Text

breakout()

Exit the mainloop but don’t destroy the master.

This stops the event loop, but window remains displayed.

cancel()

Clear contents and exit mainloop.

This stops the event loop, removes the window, and deletes the widget structure.

catchExcept()

Catch the exception messages.

Use this in a try/except block to catch any errors:

Returns:The exception message
Return type:str
close()

Close the window.

This stops the event loop and removes the window. However, the window structure can still be referenced, and the window can be redisplayed.

focus(tag)

Switch focus to the desired widget.

This is useful to select the desired widget at the beginning so the user does not have to click.

Parameters:tag (str) – Reference to widget
get(tag, allValues=False)

Get the contents of the ttwidget. With more complex widgets the programmer can choose to get all the values rather than user selected values.

Parameters:
  • tag (str) – Reference to widget, created in add*
  • allValues (bool) – if true return all the values
Returns:

Contents of ttWidget

getFrame(tag)

Get the ttk frame if present.

Get the ttk.Frame or ttk.LabelFrame of the widget so the programmer can use more advanced methods.

Parameters:tag (str) – Reference to widget
Returns:ttk/tk.Frame or ttk/tk.LabelFrame
getType(tag)

Get the type of widget.

Get the type of widget as a string. All widgets have a type.

Parameters:tag (str) – Reference to widget
Returns:Type of widget as str
getWidget(tag)

Get the tk/ttk widget if present.

Get the underlying tk or ttk widget so the programmer can use more advanced methods.

Parameter:
tag (str): - Reference to widget
Returns:ttk/tk.Widget
grid(tag=None, **tkparms)

Same as plot, some instructors prefer grid which is standard tk.

Parameters:

tag (str) – Reference to widget

Keyword Arguments:
 
  • row (int) – the row number counting from 0
  • column (int) – the column number
  • rowspan (int) – the number of rows to span
  • columnspan (int) – the number of columns to span
  • sticky (str) – the directions to fill the cell for the widget
  • padx (int) – horizontal space between widget cells (pixels)
  • pady (int) – vertical space between widget cells (pixels)
  • ipadx (int) – horizontal space within cell (pixels)
  • ipady (int) – vertical space within cell (pixels)
mainloop()

Some instructors prefer mainloop

plot(tag=None, **tkparms)

Plot the ttWidget.

Deprecated, use plotxy. Place a frame and widget in a cell of a window using the row and column. Plot was selected as an easier name for novices than grid. Tkparms are extremely useful here and should be understood. Look at the Tkinter documentation.

Parameters:

tag (str) – Reference to widget

Keyword Arguments:
 
  • row (int) – the row number counting from 0
  • column (int) – the column number
  • rowspan (int) – the number of rows to span
  • columnspan (int) – the number of columns to span
  • sticky (str) – the directions to fill the cell for the widget
  • padx (int) – horizontal space between widget cells (pixels)
  • pady (int) – vertical space between widget cells (pixels)
  • ipadx (int) – horizontal space within cell (pixels)
  • ipady (int) – vertical space within cell (pixels)
plotxy(tag=None, column=0, row=0, **tkparms)

Plot the ttWidget at column x, row y.

Place a frame and widget in a cell of a window using the column (x) and row (y). Plot was selected as an easy name for novice programmers since they are plotting widgets in a xy grid. Tkparms are extremely useful here and should be understood. Look at the Tkinter documentation.

Parameters:
  • tag (str) – Reference to widget
  • column (int) – the column number counting from 0
  • row (int) – the row number
Keyword Arguments:
 
  • rowspan (int) – the number of rows to span
  • columnspan (int) – the number of columns to span
  • sticky (str) – the directions to fill the cell for the widget
  • padx (int) – horizontal space between widget cells (pixels)
  • pady (int) – vertical space between widget cells (pixels)
  • ipadx (int) – horizontal space within cell (pixels)
  • ipady (int) – vertical space within cell (pixels)
popDialog(dtype='askopenfilename', **tkparms)

Popup a standard dialog.

This pops up a standard tk dialog.

Parameters:

dtype (str) – ‘askopenfilename’ or ‘asksaveasfilename’ or ‘askdirectory’ or ‘askcolor’message (str): Message in box

Keyword Arguments:
 
  • defaultextension (str) – extention added to filename (must strat with .)
  • filetypes (list) – entrys in file listing ((label1, pattern1), (…))
  • initialdir (str) – Initial directory (space, ‘ ‘ remembers last directory)
  • initialfile (str) – Default filename
  • title (str) – Pop-up window’s title
  • color (str) – Initial color (for askcolor)
Returns:

str or (red, green, blue) for askcolor

popMessage(message, mtype='showinfo', title='Information', **tkparms)

Popup a tk message window.

Parameters:
  • message (str) – Message in box
  • mtype (str) – ‘showinfo’ or ‘showwarning’ or ‘showerror’ or ‘askyesno’ or ‘askokcancel’ or ‘askretrycancel’
  • title (str) – Title of window
Keyword Arguments:
 
  • default (str) – ‘OK’ or ‘Cancel’ or ‘Yes’ or ‘No’ or ‘Retry’
  • icon (str) – ‘error’ or ‘info’ or ‘question’ or ‘warning’
Returns:

‘ok’ for show*, bool for ask*

refresh()

Alias for update_idletasks, better label for beginners.

This refreshes the appearance of all widgets. Usually this is called automatically after a widget contents are changed.

reset(tag)

Reset the selections in a widget

This clears any selections in a widget. This was created mainly for listboxes but is useful for all selection widgets.

Parameter:
tag (str): - Reference to widget
set(tag, value, allValues=False)

Set the contents of the widget. The programmer has the option to replace all the values or just add new values.

Parameters:
  • tag (str) –
    • Reference to widget
  • value (object) –
    • Value to set
  • allValues (bool) – if True, replace all values
setState(tag, states, index=None)

Set or clear ttk or tk widget states

Change the underlying ttk or tk widget states. For ttk widgets the states are ‘active’, ‘alternate’, background’, ‘disabled’, ‘focus’, ‘invalid’, ‘pressed’, ‘readonly’, and ‘selected’. Preceding a state with ‘!’ clears it. For tk widgets use ‘disabled’, ‘normal’, or ‘readonly’. Index parameter allows you to change an individual element in multipart widget. See Tkinter documentation.

Parameters:
  • tag (str) – Reference to widget
  • states (list) – States of widget, usually ‘disabled’ or ‘!disabled’ for ttk
  • index (int) – Index to element in multipart widget
setTitle(prompt)

Set the title for a window

This allows the programmer to set the title of the window. If this method is not used, the title will be Tk. This only works with top level windows.

Parameters:prompt (str) – The title of the window
setWidget(tag, index=None, **tkparms)

Change a tk/ttk widget attribute

Change the underlying tk or ttk widget appearance using tkparms. Index parameter allows you to change an individual element in multipart widget. See Tkinter documentation.

Parameters:
  • tag (str) – Reference to widget
  • index (int) – Index to element in multipart widget
Keyword Arguments:
 
  • justify (str) – Justification of text (‘left’ [def], ‘right’, ‘center’)
  • show (str) – Char to display instead of actual text
  • style (ttk.Style) – Style to use for widget
  • text (str) – Text inside widget
waitforUser()

Alias for mainloop, better label for beginners.

This starts the event loop so the user can interact with window.