Python Tkinter Tutorial


Python Tkinter

Tkinter is a standard Python library used for creating graphical user interfaces (GUIs). It provides a set of tools and widgets that allow developers to build interactive applications with buttons, labels, entry fields, menus, and more.

In the following sections, we cover basics of Tkinter, widgets, etc.


Tkinter Window

Window Basics

  1. Tkinter - Window example
  2. Tkinter - Set title for window
  3. Tkinter - Set window size
  4. Tkinter - Resizable window
  5. Tkinter - Non-resizable window

Window Styling

  1. Tkinter - Set window background color
  2. Tkinter - Window padding

Events

  1. Tkinter - Window resize event
  2. Tkinter - Refresh window
  3. Tkinter - Bind Escape key to close window
  4. Tkinter - Close window programmatically
  5. Tkinter - Maximized window
Tkinter Window

Tkinter Label

The Label widget in Tkinter is used to display text or images on a graphical user interface (GUI). It provides a way to present static content or information to the user.

Tkinter Label Example

The following tutorials cover the creation of labels, styling of labels, and some event handling techniques on labels.

Basics

  1. Tkinter - Label
  2. Tkinter Label - Wrap text
  3. Tkinter - Display image using Label

Styling

  1. Tkinter Label - Font size
  2. Tkinter Label - Italic text
  3. Tkinter Label - Underline text
  4. Tkinter Label - Bold text
  5. Tkinter Label - Background color
  6. Tkinter Label - Foreground color
  7. Tkinter Label - Width and height
  8. Tkinter Label - Border
  9. Tkinter Label - Center align text
  10. Tkinter Label - Left align text
  11. Tkinter Label - Right align text
  12. Tkinter Label - Background image

Events

  1. Tkinter Label - On click event
  2. Tkinter Label - Tooltip

Tkinter Button

In Tkinter, a button is a graphical user interface (GUI) widget that allows users to interact with your application by clicking on it.

A button typically represents an action or a command that can be triggered when clicked.

Button Basics

  1. Tkinter Button
  2. Tkinter - Change button text dynamically

Button Styling

  1. Tkinter Button – Change font family, font size, and style
  2. Tkinter Button - Background color
  3. Tkinter Button - Change color on mouse click

Button Events

  1. Tkinter - Call function on button click

Tkinter Entry

Tkinter Entry Widget Example

Entry widget basics

  1. Tkinter Entry
  2. Tkinter Entry - Password
  3. Tkinter Entry - Get the input value
  4. Tkinter Entry - Insert text
  5. Tkinter Entry - Delete value
  6. Tkinter Entry - Disable
  7. Tkinter Entry - Placeholder
  8. Tkinter Entry - Default text
  9. Tkinter Entry - Validation

Entry Widget Styling

  1. Tkinter Entry - Background color
  2. Tkinter Entry - Text color
  3. Tkinter Entry - Font size
  4. Tkinter - Left align text in Entry widget
  5. Tkinter - Right align text in Entry widget
  6. Tkinter - Center align text in Entry widget
  7. Tkinter Entry - Set width

Entry widget events

  1. Tkinter Entry - Handle Focus In and Focus Out events
  2. Tkinter Entry - On enter key event
  3. Tkinter Entry - On Enter/Return key focus next widget
  4. Tkinter Entry - On change

Tkinter Checkbutton

Checkbutton widget is used to allow users to select or deselect options.

Tkinter Checkbutton

The following tutorials cover the topics of how a Checkbutton is created, options of a Checkbutton, how to handle the events related to this widget, and more.

  1. Tkinter Checkbutton
  2. Tkinter Checkbutton() Options
  3. Tkinter Checkbutton - Command
  4. Tkinter - Create Checkbutton widgets from a dictionary
  5. Tkinter Checkbutton - Checked by default
  6. Tkinter Checkbutton - Disable
  7. Tkinter Checkbutton - Get selected values
  8. Tkinter Checkbutton - Set value
  9. Tkinter Checkbutton - Check if selected
  10. Tkinter Checkbutton - On change event

Tkinter Menu Widget

In Tkinter, Menus provide a way to create hierarchical navigation or actions in Tkinter-based applications. Menus offer a convenient way to organize and present various commands and options to the user.

Tkinter menu example
Tkinter Menu bar with three menus, and items in them

The following tutorials covert topics related to the Menu widget in Tkinter.

Menu Widget Basics

  1. Tkinter - Create Menu bar
  2. Tkinter - Create Menu
  3. Tkinter - Add separator in Menu
  4. Tkinter - Create submenus
  5. Tkinter - Checkbutton Menu items
  6. Tkinter - Radiobutton Menu items
  7. Tkinter - Add keyboard shortcut to menu item
  8. Tkinter - Disable menu item
  9. Tkinter - Tear-off Menu (Popup menus)

Menu Events and Actions

  1. Tkinter - Command callback function for Menu item
  2. Tkinter - Pass arguments in the command function on menu item click event
  3. Tkinter - Add icon to Menu item
  4. Tkinter - Context Menus (Popup Menus)

Advanced Menu Tutorials

  1. Tkinter - Create Menu from a list
  2. Tkinter - Create complete Menu from a list of lists

Tkinter Canvas

Canvas widget is used to draw and manipulate graphics, such as lines, shapes, text, and images, on a rectangular area.

Tkinter Canvas with rectangle and circle
Canvas with rectangle and circle
  1. Tkinter Canvas
  2. Tkinter Canvas - Create line
  3. Tkinter Canvas - Create rectangle
  1. Tkinter Canvas - Create square
  2. Tkinter Canvas - Create circle
  3. Tkinter Canvas - Create oval
  4. Tkinter Canvas - Create text
  5. Tkinter - Save canvas to image
  6. Tkinter Canvas - Wrap text
  7. Tkinter - Animation canvas

Tkinter Frame

Frame is a container widget that acts as a rectangular region to hold other widgets or groups of widgets.

Tkinter Frame
Frame with lightgreen background
  1. Tkinter Frame
  1. Tkinter - Create a frame
  2. Tkinter - Clear a frame
  3. Tkinter - Scrollable frame
  4. Tkinter - Set frame size
  5. Tkinter - Set frame background color

Tkinter Listbox

Tkinter Listbox
Tkinter Listbox with four items
  1. Tkinter Listbox
  1. Tkinter Listbox - Show scrollbar
  2. Tkinter Listbox - Select multiple items
  3. Tkinter Listbox - Set background color

Tkinter Message-box

In Tkinter, a messagebox is a pre-defined dialog box that provides a simple way to display messages or prompts to the user.

It is commonly used to show information, warnings, errors, or to ask for confirmation from the user.

  1. Tkinter messagebox
  2. Tkinter messagebox - Example
  3. Tkinter messagebox - Show info
  4. Tkinter messagebox - Show warning
  5. Tkinter messagebox - Show error
  6. Tkinter messagebox - Ask Yes or No
  7. Tkinter messagebox - Ask OK or Cancel
  8. Tkinter messagebox - Ask Yes, No, or Cancel
  9. Tkinter messagebox - Ask Retry or Cancel
  10. Tkinter messagebox - Without buttons
  11. Tkinter messagebox - showinfo() return value

Tkinter Dialogs

Tkinter prompt user for input using Simple Dialog
A simple dialog to prompt user for input

Standard Tkinter input dialogs

  1. Tkinter simpledialog - Prompt for user input

File selection dialogs

  1. Tkinter filedialog - Ask open file
  1. Tkinter filedialog - Ask open files
  2. Tkinter filedialog - Ask save as file
  3. Tkinter filedialog - Ask open filename
  4. Tkinter filedialog - Ask open filenames
  5. Tkinter filedialog - Ask save as filename
  6. Tkinter filedialog - Ask directory

Tkinter Radiobutton

Radiobutton widget is used to display a radio button. We can use a group of radio buttons to select a single option from a set of mutually exclusive options.

Tkinter Radiobutton

Basics

  1. Tkinter Radiobutton
  2. Tkinter Radiobutton - Groups
  3. Tkinter Radiobutton - Clear selection
  4. Tkinter Radiobutton - Default selection
  5. Tkinter Radiobutton - Get selected value
  6. Tkinter Radiobutton - Check if selected
  7. Tkinter Radiobutton - Select an option programmatically

Radiobutton events

  1. Tkinter Radiobutton - On change of selection

Tkinter Scale

The Scale widget in Tkinter is used to create a slider control that allows the user to select a value from a range.

Tkinter Scale widget Example
  1. Tkinter Scale
  2. Tkinter Scale - Command
  3. Tkinter Scale - Horizontal orientation

Tkinter Examples

  1. Tkinter - Login form

Python Libraries