1 minute read

How to use Tkinter to create a GUI for a Python application.

Overview

Tkinter is part of the Python standard library. It is a wrapper around the Tcl/Tk GUI. Use it to build user interfaces.

Load the library:

import tkinter as tk

Load themed widgets:

from tkinter import ttk

Window

Begin by instantiating a Tk() class to create a main window:

Parameters:

  • screenName : string (optional). Nominate which screen to use.
  • baseName : string (optional). Application name (defaults to the name of the script).

  • className : string (optional). Name of the window class to be used for stying and window manager settings.

  • useTk : boolean (optional). Indicates whether or not to intitialise the Tk subsystem. (Defaults to 1).

Instantiate an object of the Tk class:

win = tk.Tk() 

Add widgets to the window:

  • tk creates a classic widget.
  • ttk creates a themed widget.
hello_world = ttk.Label(win, text='Hello, World!')

Display the label widget in the window:

  • pack() resizes the window to the minimum bounds of the widget.
hello_world.pack()

End with the event loop:

win.mainloop() 

Further Reading

QED

© Adam Heinz

1 January 2026

Categories:

Updated: