简体   繁体   English

使用 Pyinstaller 编译后,带有 Pyscreenshot 脚本的 Python Tkinter 不运行

[英]Python Tkinter with Pyscreenshot script doesn't run after compiling with Pyinstaller

My script runs smoothly.我的脚本运行顺利。 However after compiling with Pyinstaller, launching the .exe and clicking the start button, the GUI opens once again and crashes.但是在使用 Pyinstaller 编译后,启动 .exe 并单击开始按钮,GUI 再次打开并崩溃。

def grabberfunc(*args):
    im = ImageGrab.grab()
    savedir=str(mappa)
    savefile="Screenshot_"+str("{:%Y_%m_%d-%H_%M_%S}".format(datetime.datetime.now()))+".png"
    savedirfile=join(savedir,savefile)
    im.save(str(savedirfile))

def scanning():
    interval=deftimeInput.get()
    if running:
        grabberfunc()
    root.after(int(interval)*1000, scanning)

if __name__=='__main__':
    root = tkinter.Tk()
    ...

There is a basic GUI with 2 buttons: 'Start' sets the 'running' variable 'True', the 'Stop' vice versa.有一个带有 2 个按钮的基本 GUI:“开始”设置“运行”变量“真”,“停止”反之亦然。 If the script runs the GUI doesn't open up again and runs as I want it to.如果脚本运行,GUI 不会再次打开并按我想要的方式运行。

Finally found the solution.终于找到了解决办法。

Instead of importing the pyscreenshot module, the ImageGrab module should be imported from PIL应该从PIL导入ImageGrab模块,而不是导入pyscreenshot模块

So the correct import is:所以正确的导入是:

from PIL import ImageGrab

After compiling the script by pyinstaller , the exe runs fine.通过pyinstaller编译脚本后,exe 运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM