Display Graphical Interacting Window Using Python

Display Graphical Interacting Window Using Python

Display Graphical Interacting Window Using Python (Python Tutorials : 3)

Welcome to our New Python Programming Article! Today we are going to see how to display an interacting graphical window using python programming.

In this article, we will take an example to print public ip of our network. In order to execute the code that displays the public ip, we first have to complete a password verification process. Once the password is verified we will be able to see our Public ip displayed in the terminal window.

To successfully complete this simple yet interesting project, we will make use of a library called PythonZenity. This library consists of few but amazing packages inside it. Among the packages we will use some of them in our project and have a clear understanding of what else can be done using those packages.

Here is an example code provided by Pythonzenity in their Github account. We will use the same logic to accomplish our graphical interacting project. With that said, here is the code that I somehow managed to execute.

As you can see we are importing urllib2, sys, pythonzenity library in the above code. From pythonzenity library we are importing two packages i.e. Password package for password pop up field and Message package to display verification message in the pop up window. Similarly, we are using urllib2 module to fetch the public ip address by opening the URL http://icanhazip.com.

And finally, we are importing sys module to call the exit status for the python program. What actually it means is, if you provide incorrect password then the program will get terminated with an exit status argument. Now we are defining our main() as we do in c and c++ languages. Inside main() we are storing our password into password which is lincoder.

Now we are prompting graphical interface to the user to provide the correct password. If the user provides the correct password then the program comes out of the main() and prints message verified successfully and if incase the password does not match then the program proceeds and executes the system exit status and prints the argument, Incorrect password into the terminal window.

Display Graphical Interacting Window Using Python

Display Graphical Interacting Window Using Python

Now finally the verification process gets over and our code to find the public ip gets executed and prints the ip address into the terminal window. That’s what this program is supposed to do.


That’s all in this article. Support us and be sure to check other cool stuffs.

Any kind of suggestion or questions, please drop it down in the comment section below 🙂