Basic Components of Python GUI Programming
As we know python is the most widely used programming language now a day. Several websites such as Spotify, Netflix, Uber, Dropbox, etc are developed using python. In this article we will learn to develop Graphical User Interface using Python.
As we know python is the most widely used programming language now a day. Several websites such as Spotify, Netflix, Uber, Dropbox, etc are developed using python. In this article, we will learn to develop a Graphical User Interface using Python. Python provides several options or libraries for developing graphical user interfaces (GUIs). Some of the most popular GUI options or libraries in python are Tkinter, wxPython, Python.
One of the standard GUI Python libraries is Tkinter. Python and Tkinter combined together provides a fast and easy way to create Graphical User Interface applications. The Tkinter library provides a powerful object-oriented interface to the python GUI toolkit.
Steps to create a GUI application using python,
1. Import the Tkinter library of python.
2. Create the GUI application's main window.
3. Add one or more components (such as frame, buttons) to the GUI application.
4. Enter the main event loop to take action whenever each event is triggered by the user.
top = Tkinter.Tk()
# Code to add widgets/components will be inserted here...
The Button component in Tkinter is used to add buttons in a Python application. A method or a function can be assigned to a button that is called or invoked automatically on clicking the button.
Here is the simple syntax to create button −
sp = Button ( master, option=value, ... )
The Canvas component in Tkinter is a rectangular area or plane that is used for drawing pictures or other complex graphics. One can place different components such as graphics, text or frames on a Canvas area.
Here is the simple syntax to create canvas −
sp = Canvas ( master, option=value, ... )
The Checkbutton component in Tkinter is one of the widely used component that is used to display a number of options to a user or viewer as toggle buttons from which the user can select one or more options by clicking the button corresponding to each option. The user can also display images in place of plain text.
Here is the simple syntax to create Checkbutton –
sp = Checkbutton ( master, option, ... )
The Radiobutton component in Tkinter implements a multiple-choice button, which is used to offer multiple selections options to the user. In order to implement a radiobutton, each group or option of radiobuttons must be associated with the same variable and each button must symbolize a single value. The user can use the Tab key to switch from one radionbutton to another.
Here is the simple syntax to create Radiobutton −
sp = Radiobutton ( master, option, ... )
The Menubutton component in Tkinter is the part of a drop-down menu. Every menubutton is associated with a Menu that can display the choices for that menubutton as a dropdown menu when the user clicks on it.
Here is the simple syntax to create Menubutton –
sp = Menubutton ( master, option, ... )
The Frame component in Tkinter is very important for the process of grouping and organizing other components in a somewhat visual friendly way. Frame works like a container, which is responsible for arranging the position of other components. A frame can also be used as a base class to implement complex Tkinter components.
Here is the simple syntax to create Frame −
sp = Frame ( master, option, ... )
The Label component in Tkinter implements or displays a box where you can place either text or images. The text displayed by this component can be updated at any time and it is also possible to underline a part of the text (like to identify a keyboard shortcut).
Here is the simple syntax to create Label –
sp = Label ( master, option, ... )
The Listbox component in Tinkter is used to display a list of items or options from which an end user can select a number of items or options.
Here is the simple syntax to create Listbox −
sp = Listbox ( master, option, ... )
A labelframe component is a simple container component. This component of Tkinter has the features of a frame with the ability to display a label. The primary purpose of lableframe is to act as a spacer or container for complex layouts.
Here is the simple. syntax to create Labelframe –
sp = LabelFrame( master, option, ... )
Text components in Tkinter provide advanced capabilities that allow the user to edit multiple lines of text and format it, such as changing the text color and font. In the text component, one can embed images in it because this component was designed to handle both plain and formatted text.
Here is the simple syntax to create Text −
sp = Text ( master, option, ... )
The tkMessageBox component in Tkinter is used to display different messages within a boxes in the application. The tkMessageBox components provides a number of functions such as showinfo, showwarning, showerror, askquestion, askokcancel, askyesno, and askretryignore that can be used to display an appropriate message.
Here is the simple syntax to create tkMessageBox −
tkMessageBox.FunctionName(title, message [, options])
All Tkinter components used in python have access to specific geometry management methods, which is used to organizing different components throughout the parent container area. Tkinter generally uses the following geometry manager classes.
• The pack() Method – The pack() geometry manager of Tkinter organizes different components in blocks before placing them in the parent container area.
• The grid() Method – The grid() geometry manager organizes different components in a table-like structure in the parent container area.
• The place() Method – The place() geometry manager organizes different components by placing them in a specific position in the parent container area.
**For more details about how to use Python Button and Label click the link below,
Components of python GUI
learn python GUI
Basic python GUI
Basic Python application design
Total 342 views