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