简体   繁体   中英

Python freezes upon Tkinter destroy() method

I'm trying to build simple window with buttons in Tkinter. Exit button should act with destroy() or sys.exit, but both option just lead to no response from window and only force close of Python helps. MacOs, Python 3.9

from tkinter import ttk
import sys

class App(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.attributes('-alpha',1)
        self.attributes('-topmost',True)
        self.overrideredirect(True)
        self.resizable(False,False)
        self.title('Monitor')
        self.set_ui()


    def set_ui(self):
        exit_b=ttk.Button(self,text='Exit',command=self.app_exit)
        exit_b.pack(fill=tk.X)

    def app_exit(self):
        self.destroy()
    

root=App()
root.mainloop()```

Ok, I am a moran. Sorry for being noob, and not tested earlier, just switched to Mac from Windows. I did not export file from VS code... Simply running it for a test give this results, but when I export script as a python script with.py extension and running it straight with IDLE all works fine. There is definitely some problems with interaction between VS code and Python interpreter for Apple silicon, cause it should not work like this, and its ridiculous to import script every time just to test it as you write. But at least code is working as expected.

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