1.首先需要安装一下pyinstaller的库

在cdm或者直接在vscode打开终端输入:

pip install pyinstaller

看到下图提示:Successfully installed pyinstaller-版本号,即安装成功

 如果没有成功,可能需要先更新一下pip,根据终端的报错提示可以更新后再安装。

如何用python制作软键盘 python如何制作软件_python

安装之后可以看下这个库有什么功能,直接在vscode终端输入pyinstaller可以得到使用方法

如何用python制作软键盘 python如何制作软件_Small_02

2.制作一个可执行的exe文件

当然这个exe只打印菱形有点乏味哈哈哈哈哈哈哈哈,但是这个是我实验成功的第一个exe

下面是我的进阶版的py文件——海底三剑客!

只有猜出海底三剑客,我们才是好朋友【傲娇脸】

功能大概是:窗口互动+运用turtle画图,源代码如下:

#!/usr/bin/env python
# coding=utf-8
# import turtle
# import random
# from turtle import *
# from time import sleep
# t = turtle.Turtle()
# t.speed(100)
import os
import turtle as t
import random
# from turtle import *
from time import sleep
# t = turtle.Turtle()
# t.speed(100)

# 画樱花的躯干(60,t)
def tree(branchLen, t):
    sleep(0.0005)
    if branchLen > 3:
        if 8 <= branchLen <= 12:
            if random.randint(0, 2) == 0:
                t.color('snow')  # 白
            else:
                t.color('lightcoral')  # 淡珊瑚色
            t.pensize(branchLen / 3)
        elif branchLen < 8:
            if random.randint(0, 1) == 0:
                t.color('snow')
            else:
                t.color('lightcoral')  # 淡珊瑚色
            t.pensize(branchLen / 2)
        else:
            t.color('sienna')  # 赭(zhě)色
            t.pensize(branchLen / 10)  # 6
        t.forward(branchLen)
        a = 1.5 * random.random()
        t.right(20 * a)
        b = 1.5 * random.random()
        tree(branchLen - 10 * b, t)
        t.left(40 * a)
        tree(branchLen - 10 * b, t)
        t.right(20 * a)
        t.up()
        t.backward(branchLen)
        t.down()
# 掉落的花瓣
def petal(m, t):
    for i in range(m):
        a = 200 - 400 * random.random()
        b = 10 - 20 * random.random()
        t.up()
        t.forward(b)
        t.left(90)
        t.forward(a)
        t.down()
        t.color('lightcoral')  # 淡珊瑚色
        t.circle(1)
        t.up()
        t.backward(a)
        t.right(90)
        t.backward(b)
def tree_show():
    # 绘图区域
    # 画布大小
    w = t.Screen()
    t.hideturtle()  # 隐藏画笔
    t.getscreen().tracer(5, 0)
    w.screensize(bg='wheat')  # wheat小麦
    t.left(90)
    t.up()
    t.backward(150)
    t.down()
    t.color('sienna')
    # # 画樱花的躯干
    # tree(60, t)
    # # 掉落的花瓣
    # petal(200, t)
        # 画樱花的躯干
    tree(50, t)
    # 掉落的花瓣
    petal(200, t)
    sleep(1)
    # w.exitonclick() 
    # turtle.exitonclick()
    # t.exitonclick()
    # turtle.setup(400, 300, 200, 200)   
    
def dog_show():
    # 【头部轮廓】
    # t = turtle.Turtle()
    t.pensize(5)
    t.home()
    t.seth(0)
    t.pd()
    t.color('black')
    t.circle(20, 80)  # 0
    t.circle(200, 30)  # 1
    t.circle(30, 60)  # 2
    t.circle(200, 29.5)  # 3
    t.color('black')
    t.circle(20, 60)  # 4
    t.circle(-150, 22)  # 5
    t.circle(-50, 10)  # 6
    t.circle(50, 70)  # 7
    # 确定鼻头大概位置
    x_nose = t.xcor()
    y_nose = t.ycor()
    t.circle(30, 62)  # 8
    t.circle(200, 15)  # 9
    # 【鼻子】
    t.pu()
    t.goto(x_nose, y_nose + 25)
    t.seth(90)
    t.pd()
    t.begin_fill()
    t.circle(8)
    t.end_fill()
    # 【眼睛】
    t.pu()
    t.goto(x_nose + 48, y_nose + 55)
    t.seth(90)
    t.pd()
    t.begin_fill()
    t.circle(8)
    t.end_fill()
    # 【耳朵】
    t.pu()
    t.color('#444444')
    t.goto(x_nose + 100, y_nose + 110)
    t.seth(182)
    t.pd()
    t.circle(15, 45)  # 1
    t.color('black')
    t.circle(10, 15)  # 2
    t.circle(90, 70)  # 3
    t.circle(25, 110)  # 4
    t.rt(4)
    t.circle(90, 70)  # 5
    t.circle(10, 15)  # 6
    t.color('#444444')
    t.circle(15, 45)  # 7
    # 【身体】
    t.pu()
    t.color('black')
    t.goto(x_nose + 90, y_nose - 30)
    t.seth(-130)
    t.pd()
    t.circle(250, 28)  # 1
    t.circle(10, 140)  # 2
    t.circle(-250, 25)  # 3
    t.circle(-200, 25)  # 4
    t.circle(-50, 85)  # 5
    t.circle(8, 145)  # 6
    t.circle(90, 45)  # 7
    t.circle(550, 5)  # 8
    # 【尾巴】
    t.seth(0)
    t.circle(60, 85)  # 1
    t.circle(40, 65)  # 2
    t.circle(40, 60)  # 3
    t.lt(150)
    t.circle(-40, 90)  # 4
    t.circle(-25, 100)  # 5
    t.lt(5)
    t.fd(20)
    t.circle(10, 60)  # 6
    # 【背部】
    t.rt(80)
    t.circle(200, 35)
    # 【项圈】
    t.pensize(20)
    t.color('#F03C3F')
    t.lt(10)
    t.circle(-200, 25)  # 5
    # 【爱心铃铛】
    t.pu()
    t.fd(18)
    t.lt(90)
    t.fd(18)
    t.pensize(6)
    t.seth(35)
    t.color('#FDAF17')
    t.begin_fill()
    t.lt(135)
    t.fd(6)
    t.right(180)  # 画笔掉头
    t.circle(6, -180)
    t.backward(8)
    t.right(90)
    t.forward(6)
    t.circle(-6, 180)
    t.fd(15)
    t.end_fill()
    # 【前小腿】
    t.pensize(5)
    t.pu()
    t.color('black')
    t.goto(x_nose + 100, y_nose - 125)
    t.pd()
    t.seth(-50)
    t.fd(25)
    t.circle(10, 150)
    t.fd(25)
    # 【后小腿】
    t.pensize(4)
    t.pu()
    t.goto(x_nose + 314, y_nose - 125)
    t.pd()
    t.seth(-95)
    t.fd(25)
    t.circle(-5, 150)
    t.fd(2)
    t.hideturtle()
    # t.exitonclick() 
    sleep(1)
    # turtle.exitonclick() 
    # turtle.setup(400, 300, 200, 200)  

def bgpic(self, picname=None):
    if picname is None:
        return self._bgpicname
    if picname not in self._bgpics:
        self._bgpics[picname] = self._image(picname)
    self._setbgpic(self._bgpic, self._bgpics[picname])
    self._bgpicname = picname

def Small_octopus_show(who):
    # myWin = t.Screen()
        if who=="章鱼哥":
            path=r'logo.png'
        elif who=="海绵宝宝":
            path=r'pic1.png'    
        elif who=="派大星":
            path=r'pic2.png'   
        t.setup(width=800,height=800,startx=0,starty=0)
        t.bgpic(path)     
        # turtle.setup(width=800,height=800,startx=0,starty=0)
        # turtle.bgpic(path)     
    # myWin.exitonclick()
def pen_init():
    # t.clear()
    # t.reset()
    t.clearscreen()
    t.speed(100)
    t.hideturtle()
    # t.penup()
    
def main():
    print("这里有花树杈、狗、海底三剑客(其中一个住在菠萝屋)")
    while 1: 
        choose=input("猜猜这是谁:")
        pen_init()
        if choose=="花树杈":           
            tree_show()
        elif choose=="狗":
            dog_show()
        elif choose=="章鱼哥":
            Small_octopus_show("章鱼哥")
        elif choose=="海绵宝宝":
            Small_octopus_show("海绵宝宝")     
        elif choose=="派大星":
            Small_octopus_show("派大星")         
        else:
            print('''哦吼,猜错了,要再来一次吗?再来一次请呼叫'靓仔'~''')
            q1=input()
            if q1=="靓仔":
                continue
            else:
                break
main()

os.system("pause")
#参考链接:
#参考链接:
#官方文档:https://docs.python.org/3/library/turtle.html#turtle.clearscreen

注意图片可以自行更换,更换后需要放在同一文件夹下。

3.使用pyinstaller打包exe

这里有两种样式

 样式一:不带图标

完整命令是:pyinstaller -F 文件名.py

效果如下:

如何用python制作软键盘 python如何制作软件_如何用python制作软键盘_03

样式二:带图标

完整命令是:pyinstaller -F  -i 文件名.ico 文件名.py

如何用python制作软键盘 python如何制作软件_开发语言_04

 上面展示的图有点糊,但是好像发到别人的电脑上看着图标会更清晰,可观性也高很多!(我猜可能是电脑分辨率或者缓存的问题)

我这里选择使用带图标的,图标可以参考使用这个工具获取

在线ICO图标制作,图片转换ICO图标Pro版 - 吱吱工具箱butterPig

如何用python制作软键盘 python如何制作软件_如何用python制作软键盘_05

https://www.butterpig.top/icopro注意下图的选项要选择一致喔

如何用python制作软键盘 python如何制作软件_python_06

4.效果演示

双击打开制作好的exe程序,开始互动~

如何用python制作软键盘 python如何制作软件_python_07

 互动效果

如何用python制作软键盘 python如何制作软件_开发语言_08

如何用python制作软键盘 python如何制作软件_ci_09

 

如何用python制作软键盘 python如何制作软件_开发语言_10

如何用python制作软键盘 python如何制作软件_开发语言_11

如何用python制作软键盘 python如何制作软件_如何用python制作软键盘_12

写bug出现的彩蛋:

如何用python制作软键盘 python如何制作软件_如何用python制作软键盘_13

最后就是分享给小伙伴的牛逼拉丝环节!

由于我的py文件中调用了图片,所以打包发给小伙伴的时候需要把图片一起打包出去

打包发出的文件内容如下: 

 

如何用python制作软键盘 python如何制作软件_python_14

 好啦,完结撒花~