Python provides options to develop graphical user interfaces (GUI) using Tkinter. Tkinter is a standard GUI library for Python that helps with creating GUI applications.
Tkinter provides controls, including text boxes, labels, buttons, etc. These controls are called widgets. There are fifteen types of widgets in Tkinter, each of them with different options. A few commonly used Tkinter widgets are given below:
The button widget is used to display buttons on the application. It is declared as shown below:
but = Button (parent, options = value, ...)
In the syntax above, parent
refers to the parent window and options
are the commonly used options for the button widget.
The text widget is used to display text on multiple lines. It is declared as shown below:
txt = Text(parent, width=num_characters, height=num_lines)
Here, parent
refers to the parent window, and the width
and height
create a rectangle into which the user can type the text.
The frame widget is used as a container widget that organizes the other widgets. It is declared as shown below:
fr = Frame( parent, option, ...)
Here, options
might include background color or size of the border, etc.
Other commonly used Tkinter widgets include:
Canvas: used to draw shapes (lines, polygons, rectangles, etc.).
Checkbutton: used to display a number of options as checkboxes.
Listbox: used to provide a list of options to a user.
Menu: used to provide various commands to the user.
For more details on Tkinter widgets, click here.
You can create a simple GUI application using Tkinter by following the steps given below:
Free Resources