remove widgets from grid in tkinter

后端 未结 1 888
一生所求
一生所求 2021-01-17 19:05

I have a grid in a tkinter frame which displays query results. It has a date field that is changed manually and then date is used as a parameter on the query for those resul

相关标签:
1条回答
  • 2021-01-17 19:56

    Calling the method grid_forget on the widget will remove it from the window - this example uses the call grid_slaves on the parent to findout all widgets mapped to the grid, and then the grid_info call to learn about each widget's position:

    >>> import tkinter
    # create: 
    >>> a = tkinter.Tk()
    >>> for i in range(10):
    ...    label = tkinter.Label(a, text=str(i))
    ...    label.grid(column=0, row=i)
    # remove from screen:
    >>> for label in a.grid_slaves():
    ...    if int(label.grid_info()["row"]) > 6:
    ...       label.grid_forget()
    
    0 讨论(0)
提交回复
热议问题