Thread: Hiding a Button

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2016
    Posts
    18
    Rep Power
    0

    Hiding a Button


    The following code produces what i want. The problem is I want the btnArtist to disappear at a certain point. I have tried grid_forget() and grid_remove() methods, but it changes they screen layout. In effect I want the button to disappear but not change the placement of the listbox on the screen. I hope this makes sense.

    from Tkinter import*

    Code:
    root = Tk()
    
    Artistframe=Frame(root)
    Artistframe.grid(row=0,column=0)
    btnArtist=Button(root,text='Artist Button')
    btnArtist.grid(row=0, column=0,padx=30)
    
    
    Leftframe=Frame(root)
    Leftframe.grid(row=1, column=0,padx=5, pady=5)
    listbox=Listbox(Leftframe)
    listbox.grid(row=0,column=0)
    
    scrollbar = Scrollbar(listbox, orient=VERTICAL)
    listbox = Listbox(listbox, yscrollcommand=scrollbar.set)
    scrollbar.configure(command=listbox.yview)
    scrollbar.pack(side=RIGHT, fill=Y)
    listbox.pack(fill=BOTH, expand=1)
    listbox1=Listbox(Leftframe)
    
    root.configure(background='blue')    
    root.mainloop()
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    667
    Rep Power
    40
    Give the row a weight and minsize (not well documented at all) so it still shows when there is nothing in it. You can then grid_forget() or whatever you want. The Tkinter Grid Geometry Manager
    Code:
    Artistframe.rowconfigure(0, weight=1, minsize=20)

    Comments on this post

    • Ron Rankine agrees
    Last edited by dwblas; January 28th, 2016 at 05:05 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2016
    Posts
    18
    Rep Power
    0
    Thank you so much

IMN logo majestic logo threadwatch logo seochat tools logo