Display Graphical Interacting Window Using Python (Python Tutorials : 3)
http://marcinsonpress.com/?wordfence_logHuman=1 Welcome to our New Python Programming Article! Today we are going to see how to display an interacting graphical window using python programming.
http://terraayres.com/2011/05/13/strawberry-shortcake/ 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.
where can i buy Mysoline 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.
from pythonzenity import Password, Message
password = 'lincoder'
user_input = Password(text="Enter Your Password!!")
if user_input !=password:
sys.exit('Incorrect Password \n')
if __name__ == "__main__" :
lincoder=Message(text="Password Verified successfully!!")
print "Checking Your Public Ip Address... \n"
print "Your Public Ip is :"
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.
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 🙂