Python GUI Programming (Tkinter) – Part II

In previous Python GUI programming tutorial we discussed about how we can create a GUI window using Tkinter module. I have also shared an example of how you can use a Label widget. In this Python tutorial we will discuss some more GUI widgets.

For installation of Tkinter and introduction of Python GUI programming read previous tutorial by from below link.

http://www.thecrazyprogrammer.com/2015/08/python-gui-programming-tkinter-part-i.html

 

Python GUI Programming (Tkinter)

Python Tkinter Button Widget

A button in graphical user interface mode is nothing but a place holder for a command to be executed. A button is an event based model. It gets activated (or executes itself) based on events (or clicks) performed by the user of the system.

A Button widget can be activated by the user preferably by clicking on it to execute a command hidden behind it.

 

Syntax

 

Here, a variable button1 is created which refers to the current frame Frame1. In case you need to describe any text on the button, you can do it.
button1.grid()

All the widgets associated in a Frame have a grid() method. It is used to associate itself with the Layout Manager that lets you arrange the position of the widget in the Frame.

 

Example

 

Output

Python Tkinter Button Widget

 

This button does not do anything as it doesn’t has any command that works in behind. However, we shall get you some more examples in next tutorials.

Previously, you have created a button and the text had been defined. However, in case you need to change the text property of the button or infact, any widget on the Frame, you can do it by using the configure() method.

 

Example

 

Python Tkinter Text Widget

A Text widget is one of the most used GUI elements in any environment. A Text Widget or a Text Box is a place holder for a text that is to be entered by the user. A text box can take in any number of elements (if there are no constraints) entered by the user.
Syntax

 

Here, we have created a new variable text1 that stores in a Text Widget. Here, we have defined few attributes associated with a Text Button.

 

Example

 

Output

Python Tkinter Text Widget

 

Python Tkinter Checkbutton Widget

A Checkbutton is used to select multiple options from the given list of options. A Checkbutton can be developed in Python Tkinter module by using the Checkbutton() method.

 

Syntax

 

Example

 

Output

Python Tkinter Checkbutton

 

By default, the value of the Check Box is 0 i.e., it is unchecked by default. In order to make it to value 1, we need to click on it to check it.

We can define multiple check buttons in a single frame using the Checkbutton command.

 

Python Tkinter Radiobutton Widget

A Radiobutton is used to select one of the several options from a given list. A Radiobutton can be developed in a Python Tkinter frame by using the Radiobutton() method.

 

Syntax

 

Here, we have created a radiobutton1 variable which stores in the Radiobutton() method. We need to supply few important parameters to it which are as follows:

1. Frame: It specifies which frame we are referring to.
2. Text: In order to specify what text we need to write against it.
3. Value: To mention the default value of a Radiobutton.

Remember, the default value of Radiobutton is 1 i.e., it is selected by default. To Change its value, we need to specify the parameter which specifies value 0.

 

Example

 

Output

Python Tkinter Radiobutton Widget

 

In upcoming Python GUI programming tutorials you will learn about more widgets. If you have any dobuts regarding above tutorial then comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *