单击“退出"时,Tkinker 窗口没有响应 [英] Tkinker window not responding when clicked on the "Exit"

查看:32
本文介绍了单击“退出"时,Tkinker 窗口没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Python、Tkinter 创建了一个 GUI.一切似乎都很好.我在菜单"选项卡中添加了几个选项.在文件部分,我添加了一个功能,通过单击退出按钮(虽然不是按钮,而是菜单选项)来退出 GUI.这是我写的代码.

I created a GUI using Python, Tkinter. Everything seems to be fine. I have added several options to my Menu tab. In the File section I have added a feature to exit the GUI by clickinh onto the Exit button(not the button though, but a menu option). Here is the code that I have written.

from tkinter import *
from tkinter import filedialog, RIGHT

class Filedialog:
    def directory(self):
        content = filedialog.askdirectory()
        return content



class Main(Frame):


    def __init__(self):
        self.opening_times = 0
        self.current_image = 0
        self.images = []
        self.root = Tk()
        self.root.title("Y")
        self.root.configure(bg='pale turquoise')
        self.root.geometry("800x800")
        self.frame = Frame(self.root)
        self.frame.pack(side=RIGHT)
        self.frame = Frame.__init__(self, self.root)
        self.widgets()
        self.root.mainloop()


    def widgets(self):

        self.menu = Menu(self.root)
        self.root.config(menu=self.menu)
        self.filemenu = Menu(self.menu, tearoff=False)
        self.menu.add_cascade(label="File", menu=self.filemenu)
        self.filemenu.add_separator()
        self.filemenu.add_command(label="Save")
        self.filemenu.add_separator()
        self.filemenu.add_command(label="Exit", command=self.onExit)
        #self.editmenu = Menu(self.menu, tearoff=0)
        #self.menu.add_cascade(label='Edit', menu=self.editmenu)
        #self.editmenu.add_command(label="Undo")
        #self.editmenu.add_command(label="Redo")


    def onExit(self):
        self.root.quit()



if __name__ == "__main__":
    Main()

我几乎成功了.但是当我点击退出时出现问题.该函数执行它必须执行的操作.但是 GUI 窗口没有关闭,它也在那里冻结.直到我强制从外部关闭窗口之前,根本没有任何反应.

I have almost succeeded. But the problem arises when I click on the exit. The function does what it has to. But the GUI window was not closing, also it freezes there. There was no response at all until I force the window to close externally.

我也尝试过:

self.quit()

/

self.exit()

但是响应与 GUI 冻结并且不让我做任何其他活动相同.我不得不关闭完整的程序才能再次访问.

But the response is the same as the GUI freezes and not letting me do any other activities. I had to close complete program to get the access again.

至少我没有收到错误,知道出了什么问题.

I am not getting the error at least, to know what is wrong.

请帮我找出问题所在/解决这个问题.

Please help me find out what is wrong/solve this problem.

感谢您抽出宝贵时间.

推荐答案

使用 destroy() 方法代替 quit.

这篇关于单击“退出"时,Tkinker 窗口没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆