[英]How to close a single window in Tkinter without closing the main window?
我正在为学校课程项目制作数据库应用程序。 我有一个登录屏幕,可将用户带入主菜单屏幕。 从那里,用户可以打开一个客户表格。 我希望能够使用按钮关闭表单,但是,每当我尝试这样做时,整个程序都会停止运行。 有没有人可以解决这个问题? 我附上了一段代码,其中包括应用于按钮的 quit() function 以及表单的图像。 如果您想了解更多信息,请发表评论。
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()
据我了解(我无法重现您的代码)您可能想要关闭的是w
,而不是root
,因为最后一个是您的主循环。
代替:
root.destroy()
为了:
w.destroy()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.