简体   繁体   中英

How can remove a widget and resize the main window?

I have a test app that uses Python and Tkinter to present a number of text boxes to the user using the grid layout manager.

To reduce clutter on the screen I have a Show/Hide button that removes and show several non-critical widgets:

if show_all: 
    # Display widget
    widget.grid()
else :
    # Hide widget
    widget.grid_remove()

What I would like to do next is force the main window to resize after the widgets have been modified.

Any suggestions are welcome.

By default the main window should resize, assuming the user hasn't resized the window. If the user has resized the window, you might want to rethink the need to shrink it. If they resized it, they probably want it at the size they resized it to.

Regardless, try setting the window geometry of the main window (eg: root.wm_geometry("") ) to the empty string. That will trigger the main window to re-layout its children.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM