Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between iconify() and withdraw() in Python Tkinter

Tags:

python

tkinter

I've been searching and not finding an answer as far as the differences of iconify() and withdraw() methods of Tkinter are concerned.

  • iconify() seems to "convert" the window to a taskbar icon and has a state of "iconic"
  • withdraw() seems to just remove the window from the screen, after which the window has a state of "withdrawn"

If you need to reverse the situation, you simply call deiconify() on both situations.

However, what is the real difference between the two methods and how do they essentially differ from one another? Moreover, are they applied in different situations?

like image 850
stevelaskaridis Avatar asked Apr 03 '14 10:04

stevelaskaridis


1 Answers

You've got it down correctly.

In more detail:

iconify() Turns the window into an icon (without destroying it). To redraw the window, use deiconify. Under Windows, the window will show up in the taskbar. When the window has been iconified, the state method returns “iconic”.

withdraw() Removes the window from the screen (without destroying it). To redraw the window, use deiconify. When the window has been withdrawn, the state method returns “withdrawn”.

Source: Tkinter -- Toplevel Window Methods

As far as use-cases go, you would normally use iconify() in situations where you want the user to be able to easily gain access to a window that was "minimized" (via iconify()) for whatever reason. For example, say a user clicks a button that "minimizes" a window and opens up a new one. Using iconify() lets the user do whatever they need to do in the new window and then return to the previous one easily since it appears to them as an icon.

On the other hand, withdraw() is useful to "hide" windows. For example, I have developed some applications that automatically created multiple windows on start-up of the application. If I had used iconify() the user would be aware of all the windows that had been created because they'd see them as icons. Imagine the shock of a user seeing 10 windows by simply starting up an application! Therefore, I used withdraw() so that each window would appear (via deiconify()) only if the user triggered the right event.

like image 151
SizzlingVortex Avatar answered Nov 14 '22 22:11

SizzlingVortex