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.