Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

python - Showing and Hiding widgets

How do you show and hide widgets in Tkinter? I want to have an entry box, but not have it shown at all times. Can someone show me the functions to show and hide entry widgets and other widgets in tkinter? I want to be able to do this without having multiple frames.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This has been answered before on stackoverflow. The short answer is, you can use grid_remove which will cause the widget to be removed if it was previously added via grid. grid_remove remembers where the widget was, so a simple grid() will put it back without having to re-specify all of the options.

You can also use pack_forget (if using pack) and grid_forget (if using grid). These work similarly to grid_remove except they cause all of the settings to be forgotten, which means you have to explicitly place it back into the proper place on the screen.

Another option is to take advantage of the stacking order of widgets. You can use the lower method to hide the widget behind its parent, and lift to raise it above. See this answer for an example.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...