且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Tkinter 中有什么方法可以使小部件不可见吗?

更新时间:2022-12-18 21:23:48

您可能对 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()