Tkinter is a graphical user interface (GUI) module for Python, you can make desktop apps with Python. You can make windows, buttons, show text and images amongst other things.
Tk and Tkinter apps can run on most Unix platforms. This also works on Windows and Mac OS X.
The module Tkinter is an interface to the Tk GUI toolkit.
Related course: Python Desktop Apps with Tkinter
Example
Tkinter module
This example opens a blank desktop window. The tkinter module is part of the standard library.
To use tkinter, import the tkinter module.
1 | from tkinter import * |
This is tkinter with underscore t, it has been renamed in Python 3.
Setup the window
Start tk and create a window.1
2root = Tk()
app = Window(root)
The window class is not standard, we create a Window. This class in itself is pretty basic.1
2
3
4class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
Then set the window title and show the window:1
2
3
4
5# set window title
root.wm_title("Tkinter window")
# show window
root.mainloop()
Tkinter window example
The program below shows an empty tkinter window.
Run with the program below:
1 | from tkinter import * |