【问题标题】:How to close a single window in Tkinter without closing the main window?如何在不关闭主窗口的情况下关闭 Tkinter 中的单个窗口?
【发布时间】:2021-04-17 13:53:54
【问题描述】:

我正在为学校课程项目制作数据库应用程序。我有一个登录屏幕,可将用户带入主菜单屏幕。从那里,用户可以打开一个客户表格。我希望能够使用按钮关闭表单,但是,每当我尝试这样做时,整个程序都会停止运行。有没有人可以解决这个问题?我附上了代码的 sn-p,其中包括应用于按钮的 quit() 函数以及表单的图像。如果您想了解更多信息,请发表评论。

def vp_start_gui():
    '''Starting point when module is the main routine.'''
    global val, w, root
    global prog_location
    prog_call = sys.argv[0]
    prog_location = os.path.split(prog_call)[0]
    root = tk.Tk()
    top = CustomerForm (root)
    CustomerForm_support.init(root, top)
    root.mainloop()

w = None
def create_CustomerForm(rt, *args, **kwargs):
    '''Starting point when module is imported by another module.
       Correct form of call: 'create_CustomerForm(root, *args, **kwargs)' .'''
    global w, w_win, root
    global prog_location
    prog_call = sys.argv[0]
    prog_location = os.path.split(prog_call)[0]
    #rt = root
    root = rt
    w = tk.Toplevel (root)
    top = CustomerForm (w)
    CustomerForm_support.init(w, top, *args, **kwargs)
    return (w, top)


class CustomerForm:
    def quit(self):
        root.destroy()

【问题讨论】:

标签: python sqlite user-interface tkinter


【解决方案1】:

据我了解(我无法重现您的代码)您可能想要关闭的是 w,而不是 root,因为最后一个是您的主循环。

替换:

 root.destroy()

为:

 w.destroy()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多