Tkinter ("Tk Interface")is python's standard cross-platform package for creating graphical user interfaces (GUIs). It provides access to an underlying Tcl interpreter with the Tk toolkit, which itself is a cross-platform, multilanguage graphical user interface library.
Tkinter isn't the only GUI library for python, but it is the one that comes standard. Additional GUI libraries that can be used with python include wxPython, PyQt, and kivy.
Tkinter's greatest strength is its ubiquity and simplicity. It works out of the box on most platforms (linux, OSX, Windows), and comes complete with a wide range of widgets necessary for most common tasks (buttons, labels, drawing canvas, multiline text, etc).
As a learning tool, tkinter has some features that are unique among GUI toolkits, such as named fonts, bind tags, and variable tracing.
Tkinter is largely unchanged between python 2 and python 3, with the major difference being that the tkinter package and modules were renamed.
In python 2.x, the tkinter package is named Tkinter
, and related packages have their own names. For example, the following shows a typical set of import statements for python 2.x:
import Tkinter as tk
import tkFileDialog as filedialog
import ttk
Although functionality did not change much between python 2 and 3, the names of all of the tkinter modules have changed. The following is a typical set of import statements for python 3.x:
import tkinter as tk
from tkinter import filedialog
from tkinter import ttk
These examples assume that tkinter has been imported with either import tkinter as tk
(python 3) or import Tkinter as tk
(python 2).
These examples assume that tkinter has been imported with either import tkinter as tk
(python 3) or import Tkinter as tk
(python 2).
Reference:
To turn the above example into a “button box” rather than a set of radio buttons, set the indicatoron option to 0. In this case, there’s no separate radio button indicator, and the selected button is drawn as SUNKEN instead of RAISED:
Syntax assumes a widget
accepted by the method .after
has been previously created (i.e widget=tk.Label(parent)
)
These examples assume that tkinter has been imported with either import tkinter as tk
(python 3) or import Tkinter as tk
(python 2).
These examples assume that tkinter has been imported with either import tkinter as tk
(python 3) or import Tkinter as tk
(python 2).
It is also assumed that ttk has been imported with either from tkinter import ttk
(python 3) or import ttk
(python 2).