Skip to content

Latest commit

 

History

History
59 lines (33 loc) · 2.24 KB

工具.gui.pc.md

File metadata and controls

59 lines (33 loc) · 2.24 KB

图形小工具的创建与打包

一、图形程序

import tkinter as tk  # 导入tkinter模块。为了方便后续讲解,命名为 tk。
import tkinter.messagebox  # 引入弹窗库,防止解释器弹出报错。
# from random_select import pair
import random_select

window = tk.Tk()  # 生成主窗口,命名 window
window.title('Test Window')  # 定义主窗口标题
window.geometry('300x200')  # 定义主窗口的长宽

print(random_select.pairs)


def display_messagebox():  # 定义一个响应函数,目前内容为空
  student = ['郑萍军', '唐鑫', '黎少忠', '余光生', '莫少华']  # 定义列表这里存放你要点名同学的名字
  text = random_select.pairs(student)
  tk.messagebox.showinfo(title='结果', message=text)  # 消息提醒弹窗,点击确定返回值为 ok


# 定义一个按钮,用来后续触发弹窗,为了方便直接pack()吧。
tk.Button(window, text='随机匹配', command=display_messagebox).pack()

window.mainloop()  # 主窗口循环运行
Error: Session cannot generate requests

at w.executeCodeCell (/Users/apple/.vscode/extensions/ms-toolsai.jupyter-2021.9.1001312534/out/client/extension.js:52:301180)

at w.execute (/Users/apple/.vscode/extensions/ms-toolsai.jupyter-2021.9.1001312534/out/client/extension.js:52:300551)

at w.start (/Users/apple/.vscode/extensions/ms-toolsai.jupyter-2021.9.1001312534/out/client/extension.js:52:296215)

at runMicrotasks (<anonymous>)

at processTicksAndRejections (internal/process/task_queues.js:93:5)

at t.CellExecutionQueue.executeQueuedCells (/Users/apple/.vscode/extensions/ms-toolsai.jupyter-2021.9.1001312534/out/client/extension.js:52:310950)

at t.CellExecutionQueue.start (/Users/apple/.vscode/extensions/ms-toolsai.jupyter-2021.9.1001312534/out/client/extension.js:52:310490)

二、封装

pip3 install pyinstaller

在终端中cd 到项目路径,也就是main函数所在文件main.py, 切换完成后依次输入下面命令:

  • sudo pyinstaller --windowed --onefile --clean --noconfirm main.py
  • sudo pyinstaller --clean --noconfirm --windowed --onefile main.spec