在 Tkinter 中有什么方法可以使小部件不可见吗? [英] In Tkinter is there any way to make a widget not visible?

查看:49
本文介绍了在 Tkinter 中有什么方法可以使小部件不可见吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这样的东西,会使小部件正常显示:

Something like this, would make the widget appear normally:

Label(self, text = 'hello', visible ='yes') 

虽然像这样,会使小部件根本不出现:

While something like this, would make the widget not appear at all:

Label(self, text = 'hello', visible ='no') 

推荐答案

您可能对 pack_forgetgrid_forget 小部件的方法.在下面的例子中,按钮在点击时消失

You may be interested by the pack_forget and grid_forget methods of a widget. In the following example, the button disappear when clicked

from Tkinter import *

def hide_me(event):
    event.widget.pack_forget()

root = Tk()
btn=Button(root, text="Click")
btn.bind('<Button-1>', hide_me)
btn.pack()
btn2=Button(root, text="Click too")
btn2.bind('<Button-1>', hide_me)
btn2.pack()
root.mainloop()

这篇关于在 Tkinter 中有什么方法可以使小部件不可见吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆