Programmers prevent cutting leeks on Valentine's Day

How can programmers avoid cutting leeks and buying flowers on Valentine's Day? That's impossible, so write a fancy code yourself, and then generate an executable file and send it to your girlfriend, wouldn't it be Xiangxiang?
First configure the turtle environment in pycharm, steps:
file——Settings——Project Interpreter (under the Project project)—click the "+" sign—search for turtle—download—running environment

import turtle as t

# 设置窗口大小

t.setup(1000, 1000, 0, 0)

# 花

t.penup()

t.goto(-90, 100)

t.pendown()

t.color("red")

t.write("e", font=("consolas", 52, "normal"))

t.penup()

t.goto(-107, 35)

t.pendown()

t.write("U", font=("consolas", 100, "normal"))

t.end_fill()

# 根

t.color("brown")

t.penup()

t.goto(-70, 70)

t.pendown()

t.pensize(10)

t.goto(-70, -100)

# 叶子1

t.color("green")

t.penup()

t.goto(-70, -60)

t.pendown()

t.goto(-120, -40)

# 叶子2

t.penup()

t.goto(-70, -10)

t.pendown()

t.goto(-20, 20)

t.penup()

t.goto(0, 20)

t.pendown()

t.write("XXX,I Love You", font=("consolas", 15, "bold"))

t.done()

After running, you can make a rose, and there are text instructions! ! !

But you think that's the end of it? You might say in your heart, that's it? that's it ?
of course not

Next, carry on the operation, please bring a meal, it may be a meal,
our next operation is to generate an executable file, your boyfriend or girlfriend can run it directly with the computer, and then use your boyfriend or girlfriend's photo as Executable icon. (I don't think female programmers would do this kind of thing...)

The first step
to install pyinstaller
is to first download pyinstaller in python (how to configure the environment above, just replace turtle with pyinstaller and it will be ok)
and then install pyinstaller on the computer terminal (what computer terminal don’t know? Try win+R, Enter cmd), enter the following code

pip install pyinstaller

After the computer installation is complete, enter

pip show pyinstaller

This appears, indicating that the installation is ok
insert image description here

Then, it’s time to start the whole operation.
Enter the code in the terminal to generate the exe file
insert image description here

输入     pyinstaller -F XXXX.py

–icon=图标路径(pyinstaller -F --icon=my.ico XXXX.py)
-F 打包成一个exe文件
-w 使用窗口,无控制台
-c 使用控制台,无窗口
-D 创建一个目录,里面包含exe以及其他一些依赖性文件 
注:XXXX是你的工程名

Well, after writing this, you definitely don’t know how to write it. The above example:
First, I want to generate an .exe file

pyinstaller -F -w main.py

-F is to generate .exe file, -w is to use window, no console, main.py is the project name
ps: Old irons, you must pay attention here, it is best to add a -w to turn off the console, otherwise The file sent to others pops up a console, which is a bit annoying. . .

Next, make an icon for our file
Note: The icon must be in the .ico file format! ! ! ! ! ! ! ! ! (The blogger is digging a hole here, Gan, it’s true that I’m making a wave of mentality here) (What? The computer can’t convert the .ico file? Try using a format factory or a web image online professional).
Put the .ico file under the folder (OK, I guess you definitely don’t know how to put it: two methods, the first one is directly pasted in under the project file under pycharm, the second method is to click show in Explorer in pycharm Directly enter the root file, as shown in the figure below, it is recommended to open it first, and then you need to use it)
insert image description here
code:

pyinstaller --icon=1.ico -F -w main.py

1.ico is the name of the ico file you made yourself. -F, and -w (case-sensitive Austrians), there are instructions above, main.py is your project name
After finishing, click
insert image description here
to enter here
insert image description here
Click dist, your old man's .exe file is under this folder
insert image description here
After double-clicking (there is a small animation, the duration can be modified by yourself, it is a bit troublesome to upload videos on csdn, bloggers are too lazy to change to the video formats supported by csdn):
insert image description here

It’s ok to send it to your old man’s girlfriend or boyfriend. If you have any questions, please leave a message. The blogger will read the blog from time to time! I wish everyone an early birth to a precious son and live a long life together

Guess you like

Origin blog.csdn.net/qq_45156021/article/details/119706487