简体   繁体   中英

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.

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. If the script runs the GUI doesn't open up again and runs as I want it to.

Finally found the solution.

Instead of importing the pyscreenshot module, the ImageGrab module should be imported from PIL

So the correct import is:

from PIL import ImageGrab

After compiling the script by pyinstaller , the exe runs fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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