I have a python script which creates a GUI Window using Tkinter. After creation of the window and reading input I expect the execution to proceed to the while loop, but the execution never resumes as the window isn't destroyed. I want it to resume after the input is read. But here after displaying "You entered xxxx" the screen freezes and execution never gets back to the former while loop. How do I fix this? I don't want to create the window everytime
from PIL import ImageGrab, Image
from glob import glob
from io import BytesIO
import time
import tkinter as tk
window = None
entry = None
window_created = False
x = None
name_of_file = None
input_wait = False
def handle_click(event):
global name_of_file
name_of_file = entry.get()
print("You Entered " + name_of_file)
entry.delete(0, tk.END)
hide_window(window)
def show_window(window):
window.update()
window.deiconify()
def hide_window(window):
window.update()
window.withdraw()
def create_window():
global window
global entry
window = tk.Tk()
window.geometry("600x600")
window.title("Name for your image")
label = tk.Label(text="What do you want to name the image?")
entry = tk.Entry()
button = tk.Button(text="Create")
button.bind("<Button-1>", handle_click)
window.bind("<Return>", handle_click)
label.pack()
entry.pack()
button.pack()
window.mainloop()
while True:
print("Looping")
image_list = map(Image.open, glob('*.png'))
presentItem = ImageGrab.grabclipboard()
if presentItem is not None:
with BytesIO() as f:
presentItem.save(f, format='PNG')
x = Image.open(f)
if x not in image_list:
print("New item found")
if not window_created:
create_window()
window_created = True
print("Resumes")
else:
show_window(window)
print("Resumes")
presentItem.save(name_of_file + '.png', 'PNG')
else:
print("No item in clipboard")
time.sleep(0.1)