如何摆脱 Python Tkinter 根窗口? [英] How do I get rid of Python Tkinter root window?

查看:60
本文介绍了如何摆脱 Python Tkinter 根窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您知道隐藏或以任何其他方式摆脱由 Tk() 打开的出现的根窗口的巧妙方法吗?我只想使用普通对话框.

Do you know a smart way to hide or in any other way get rid of the root window that appears, opened by Tk()? I would like just to use a normal dialog.

我应该跳过对话框并将所有组件放在根窗口中吗?是否可能或可取?或者有更聪明的解决方案吗?

Should I skip the dialog and put all my components in the root window? Is it possible or desirable? Or is there a smarter solution?

推荐答案

可能绝大多数基于 tk 的应用程序都将所有组件放在默认的根窗口中.这是最方便的方法,因为它已经存在.选择隐藏默认窗口并创建自己的窗口是一件非常好的事情,尽管它只需要一点点额外的工作.

Probably the vast majority of of tk-based applications place all the components in the default root window. This is the most convenient way to do it since it already exists. Choosing to hide the default window and create your own is a perfectly fine thing to do, though it requires just a tiny bit of extra work.

要回答有关如何隐藏它的具体问题,请使用 withdraw 根窗口的方法:

To answer your specific question about how to hide it, use the withdraw method of the root window:

import Tkinter as tk
root = tk.Tk()
root.withdraw()

如果您想让窗口再次可见,请调用 deiconify(或 wm_deiconify)方法.

If you want to make the window visible again, call the deiconify (or wm_deiconify) method.

root.deiconify()

完成对话框后,您可以使用 销毁方法:

Once you are done with the dialog, you can destroy the root window along with all other tkinter widgets with the destroy method:

root.destroy()

这篇关于如何摆脱 Python Tkinter 根窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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