I got this error a little bit ago, so I started putting code into main, which temporarily fixes the problem. But now I have run into a roadblock as it seems to fail to run code outside of my script? For anyone wondering, it will be a screenshot tool, i have code working for the screenshot part and i am halfway through the cropping part but i wanted to merge the two together haha
main:
if __name__ == '__main__':
def listen():
with Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()
def on_press(key):
print('{0} pressed'.format(
key))
def on_release(key):
print('{0} release'.format(
key))
if key == Key.print_screen:
im = pysc.grab()
im.save('P:/Python/temp/screenshot.png')
print("------------------- Screenshot exported -------------------")
WIDTH, HEIGHT = 1919, 1079
BACKGROUND = 'grey'
TITLE = ' '
root.title(TITLE)
root.geometry('%sx%s' % (WIDTH, HEIGHT))
root.configure(background=BACKGROUND)
root.attributes("-fullscreen", True)
app = Application(root, background=BACKGROUND)
app.pack(side=tk.TOP, fill=tk.BOTH, expand=tk.TRUE)
app.mainloop()
listen()
Error:
File "P:\Python\screenshotselection - Copy.py", line 217, in on_release
root.title(TITLE)
File "C:\Program Files (x86)\Python38-32\lib\tkinter\__init__.py", line 2217, in wm_title
return self.tk.call('wm', 'title', self._w, string)
RuntimeError: main thread is not in main loop