Python made a small clock, and converted to exe executable programs Detailed

I. Introduction
Python written program, rely on command to execute too LOW, too low-key, not gorgeous.

Say someone else's computer, are not Python library, how to perform, but also can not be happy to play together.

So even if only to write a HelloWorld, also ended up exe program to facilitate the great cause of the spread code.

You need to use tools: pyInstaller, pypiwin32.

Second, the installation pyInstaller

1. Open a cmd window, execute the command: PIP install pyinstaller

Installing collected packages: future, pefile, altgraph, macholib, pywin32-ctype
s, pyinstaller
Running setup.py install for future ... done
Running setup.py install for pefile ... done
Running setup.py install for pyinstaller ... done
Successfully installed altgraph-0.16.1 future-0.17.1 macholib-1.11 pefile-2019.4
.18 pyinstaller-3.4 pywin32-ctypes-0.2.0

2. Alternatively, you can:

Visit the Web site: http://www.pyinstaller.org/downloads.html  , select the zip file unzip the windows

Description: windows may be under decompression tar.gz package, method:

①, decompression tool mounting 7Z;
②, right-click "to the Add Archive";
③, select compression format is the tar;
④, decompression a.tar, "Extract Here"

Third, the installation pypiwin32

In Python, window API calls broadly divided into two methods: 1.Python third-party libraries:. Pywin32; 2 references windowAPI dynamic link library; recommend the first method

Open cmd window, enter the command: PIP install pywin32. If the command can not pip, Check environment configuration, or directly to the switching installation path Python scripts:

 You can use the command: pip list to check whether the installation was successful.

In the Scripts directory execute the command: python pywin32_postinstall.py -install

 

 

 Fourth, the production of the clock applet clock.py

 

 Attached Python3.7 Source:

Tkinter Import 
Import Time

Top tkinter.Tk = () # Create a form Top
top.title ( "Clock")

label_tk = tkinter.Label (Top,
text = "the Hello",
BG = "Pink", fg = "Blue" ,
font = ( "Arial", 20 is),
The justify = "left",
) # create widgets
DEF getTime ():
var = The time.strftime ( '% Y-M-% D%% H:% M:% S ', time.localtime (the time.time ()))
top.after (1000, getTime)
label_tk.config (text = var)
label_tk.pack () # widget is placed into the main window
getTime ()
top.mainloop ( )

 Five, made into exe program execution

1. Locate the installation directory pyinstaller pip way, and went to the Python Scripts directory under the installation directory, there are two related files in the directory: pyinstaller.exe and pyinstaller-script.py, would be to use the latter.

2. clock.py into this directory

3. CMD into said directory in the command line, and execute the command: Python pyinstaller -script.py -F clock.py

C:\Users\admin\AppData\Local\Programs\Python\Python37\Scripts>python pyinstaller-script.py -F clock.py

This will generate clock.exe, Scripts stored in the following dist directory.

4. Double build directory C: clock.exe \ Users \ admin \ AppData \ Local \ \ Python \ Python37 \ Scripts \ under Programs dist 

Program to run.

reference:

https://www.cnblogs.com/panyangduola/p/8277727.html

https://blog.csdn.net/woshisangsang/article/details/73230433

https://blog.csdn.net/tangdaxue43/article/details/84840643

Guess you like

Origin www.cnblogs.com/jintianniu/p/11005912.html