Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get rid of Python Tkinter root window?

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?

like image 748
Jonas Byström Avatar asked Sep 10 '09 15:09

Jonas Byström


People also ask

What does root withdraw do Tkinter?

Tkinter withdraw method hides the window without destroying it internally. It is similar to the iconify method that turns a window into a small icon.

What is root window in Python?

According to the conventions, the root window in Tkinter is usually called "root", but you are free to call it by any other name. The third line executed the mainloop (that is, the event loop) method of the root object. The mainloop method is what keeps the root window visible.

What is Deiconify?

1. deiconify() Displays the window, after using either the iconify or the withdraw methods.


1 Answers

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.

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() 

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() 
like image 133
Bryan Oakley Avatar answered Sep 27 '22 18:09

Bryan Oakley