script2 displays image , and closes image after spacebar being pressed. script2 works alone.
unfortunately when use script1 launch script2, have click/refocus image window before i'm able close image spacebar.
i've tried using win32gui module refocus generated image window separate script (focus.py). if run focus.py myself when image being displayed, i'm able press spacebar , image window closes. i've not been able import focus.py script script2.py succesfully (so have script1.py , script2.py.
script1: action = raw_input("pick scenario: ") if action == "1": execfile("script2.py") else: print "try again." return self
script2: import os, sys import tkinter pil import image, imagetk def close_window(event): event.widget.quit() root = tkinter.tk() root.bind("<space>", close_window) imagefile = "image1.png" image1 = image.open(imagefile) root.geometry('%dx%d' % (image1.size[0],image1.size[1])) tkpi = imagetk.photoimage(image1) label_image = tkinter.label(root, image=tkpi) label_image.place(x=0,y=0,width=image1.size[0],height=image1.size[1]) root.mainloop()
focus.py import win32gui tk = win32gui.findwindow(none, 'tk') win32gui.setforegroundwindow(tk)
Comments
Post a Comment