python - 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()
解决方案
尝试 command = sys.exit 而不是 command = quit。在顶部添加“import sys”。
推荐阅读
- rust - 获取对不可变变量的可变引用?
- tensorflow - 如何替换张量流数组中的值
- python-3.x - 使用python中的字典计算每个字符的频率
- ios - 导出 XLIFF 文件似乎缺少一些用于本地化的 .strings 和 .stringsdict 文件
- ruby-on-rails - 如何显示已上传到 spree(RoR) 横幅的图像?
- javascript - 在 ES6 中使用 ES5 模块时,__webpack_require__(...) 不是函数
- sql - 需要一个枢轴函数来显示分支明智的项目总库存数量(分支作为列,项目作为行和袜子数量的总和作为数据)
- node.js - Firebase 函数在尝试写入存储时抛出错误
- r - R中count.fields函数中的quote =“”是什么意思?
- api - 为什么在资源 ID 的开头使用首字母缩略词?