Hide and Unhide The Window in Tkinter - Python

Hide and Unhide The Window in Tkinter - Python

To hide (withdraw) and unhide (deiconify) the main window in a tkinter application, you can use the withdraw() and deiconify() methods respectively.

Here's a simple demonstration using tkinter where we create a main window with two buttons. One button hides the window, and the other unhides it:

import tkinter as tk def hide_window(): root.withdraw() def show_window(): root.deiconify() root = tk.Tk() root.title("Hide and Unhide") # Button to hide the main window hide_btn = tk.Button(root, text="Hide Window", command=hide_window) hide_btn.pack(pady=20) # Button to show the main window show_btn = tk.Button(root, text="Show Window after 5 seconds", command=lambda: (hide_window(), root.after(5000, show_window))) show_btn.pack(pady=20) root.mainloop() 

In this example:

  • Clicking "Hide Window" will directly hide the main window.

  • Clicking "Show Window after 5 seconds" will first hide the window and then unhide it after 5 seconds.

You can adapt this code for more complex use cases as per your needs.


More Tags

codeigniter-2 edit wc uiviewcontroller one-to-one parquet ansible-template elementwise-operations phone-call culture

More Programming Guides

Other Guides

More Programming Examples