[Appetizer essay]python Tkinter implement a simple ping command

Source: Internet
Author: User

This article is mainly about the Python graphical interface of the key and the actual function of the docking, in fact, the program mastered the foundation after the study should be on their own to dig other

Most of the online discovery of the tutorial is 2, so this article uses python3.5, in fact, there is no difference, there are some support library changes just

First we use Python to write a simple window program with a button, such as

 from Import # Import TK Package  import os  # Imports OS package, easy to execute cmd command, online there are other methods to execute  = Tk ()  #  Create a window program test.title ('ping')  # for this window program named
def testping ():  # defines a module called Ping, which is actually to implement the ping command    os.system ('Ping www.baidu.com')  # Direct ping Baidu

# the above modules are not actually executed and need to be called elsewhere . # Create a button, the method of using the module in the key, internal parameters can be adjusted, specifically, please understand the TK button button (test, text=" Network Monitor ", command = testping). Pack () Test.mainloop ()

Created window programs such as

If the feeling size is inappropriate, you can use, such as Test.geometry (' X-ray ') to set the window to the size of the pixel, remember that × is the letter is not a symbol, window parameters here not much to say

Now let's see if clicking on the Network Monitor button does the required functionality.

So, in a graphical interface to implement the ping command is done, is it simple?

In fact, a good function is not only necessary, for example, you may need to ping the window to keep it, or get ping return value in real time, export ping test log, etc.

Because I am also a bitter force of tester, time is limited, today to share here, the procedure is relatively simple, mainly to enlighten the thinking

If the program found in PY 2 error, please note that py2 in the Tkinter package is actually Tkinter, the method and parameters are roughly the same, if you encounter version problems in the course of learning TK, you can refer to the method

Check if the package has been updated between 2 and 3, adjust the code with the actual situation

Version to implement, the learning process to install the dual version of Python is also possible

[Appetizer essay]python Tkinter implement a simple ping command

Related Article

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.