displaying graphical interactive windows using Python

Source: Internet
Author: User

This article mainly explains how to usePython Programming (http://www.maiziedu.com/course/python/) displays an interactive graphics window. As an example, print a public IP Network. in order to execute code to display the public IP, We first need to complete the password verification process. Once the password is verified we will be able to see our public IP displayed in the terminal window.

in order to successfully complete this simple and interesting project , We will use a library called pythonzenity . This library contains very few things but there are some magical packages inside. In the package , We will use some of these packages in our project , and we will have a clear understanding of what else we can do with this package.

A sample code is provided here in pythonzenity 's Github account. We will use the same logic to implement our graphical interaction project. Having said so much , Here is my code execution.

#!/usr/bin/env python

Import Urllib2
Import SYS
From pythonzenity import Password, Message
def main ():
password = ' Lincoder '
user_input = Password (text= "Enter Your password!!")
if User_input!=password:
sys.exit (' incorrect Password \ n ')
if __name__ = = "__main__":
Main ()
lincoder=message (text= "Password verified successfully!!")
Print Lincoder
print "Checking Your public Ip address ... \ n"
print "Your public Ip is:"
Print (Urllib2.urlopen (' http://icanhazip.com '). Read ())

as you can see in the above code we import urllib2, sys, pythonzenity Library. Two packages were imported from the Pythonzenity library. The password package is used for the password popup field and the message packet is used to render the validation information in the popup window. Similarly , We use the urllib2 module to get the public IP address open URL http// Icanhazip.com.

Finally, we import the SYS module in the python program to invoke the exit state. It actually means that if you provide an incorrect password , the program terminates with the exit status parameter. Now we define our main function main () Just as we define the main function in the C or C + + language. In main () We store the password in the password lincoder.

now we are prompting the graphical interface to provide the user with the correct password. If the user provides the correct password , then the program comes to main () and the print message is validated successfully , If the password does not match , The program result executes the system exit status and prints the parameters and incorrect passwords in the terminal window.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7E/77/wKioL1cBxGDx1N8ZAADpk2v22dA303.png "title=" Qq20160330155621.png "alt=" Wkiol1cbxgdx1n8zaadpk2v22da303.png "/>

Now the final verification process is over , Our code finds the public IP, executes the IP address, and prints it to the terminal window. That's what this program should do.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7E/7B/wKiom1cBw9DB5jQKAABas8G4Gss671.png "title=" Qq20160330155713.png "alt=" Wkiom1cbw9db5jqkaabas8g4gss671.png "/>

displaying graphical interactive windows using Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.