首页 > 解决方案 > Python 文件在 IDLE 中运行,但不是作为 EXE

问题描述

所以我制作了这个简单的脚本来帮助我在 Microsoft Teams 中演示时重新分享我的幻灯片(我是 Python 的初学者,如果这很简单,很抱歉),并且从我的 IDE 执行时它工作得很好(PyCharm,如果有帮助的话) 并处于空闲状态。但是,当我使用 pyinstaller 将其编译为 exe 时,它​​根本无法工作。更具体地说,它表示未定义名称quit 。

下面是代码:

from tkinter import Tk, Button
import pyautogui as pyg
import time


def reshare():
    pyg.doubleClick(x=1766, y=945)
    pyg.hotkey('ctrl', 'shift', 'e')
    pyg.doubleClick(x=563, y=698)
    time.sleep(0.2)
    pyg.hotkey('ctrl', 'shift', 'e')
    pyg.doubleClick(x=331, y=696)



root = Tk()
Label1 = Button(root, text="Re-share", command=reshare)
Label2 = Button(root, text="Quit", command=quit)
Label1.pack(side="top")
Label2.pack(side="bottom")
root.mainloop()

标签: pythontkinter

解决方案


尝试 command = sys.exit 而不是 command = quit。在顶部添加“import sys”。


推荐阅读