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

    Join Date
    May 2013
    Posts
    24
    Rep Power
    0

    Help with tkinter grid


    I have the following code:

    Code:
    #!/usr/bin/python
    
    from Tkinter import *
    
    root = Tk()
    root.geometry('500x300')
    
    frame_one = Frame(root)
    frame_one.grid(row=0, column=0)
    
    button_one = Button(root, text="ONE")
    button_one.grid(row=1, column=1, padx=10, pady=10)
    
    root.mainloop()
    and when I change the row in the button_one to:

    Code:
    button_one.grid(row=2, column=1, padx=10, pady=10)
    the button does not move down to another row as I am wanting. How do I get the button to move down to a different row? I am not understanding the grid layout manager. I have read tutorials, but I still don't know why I can't get the widgets to move down rows. The row and column options seem to not do anything at all.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    524
    Rep Power
    34
    Tkinter does not display empty columns or rows, so even though the button is moved down one row, the row above is not displayed because it is empty. Note what happens when a label is placed in a row so the row is also displayed.
    Code:
    from Tkinter import *
    
    root = Tk()
    root.geometry('500x300')
    
    button_one = Button(root, text="ONE")
    button_one.grid(row=1, column=1, padx=10, pady=10)
    
    Label(root, text="").grid(row=0, column=0)  ## display empty row 
    Label(root, text="Row 1").grid(row=1, column=0)
    
    button_one.grid(row=2, column=1, padx=10, pady=10)
    
    root.mainloop()

IMN logo majestic logo threadwatch logo seochat tools logo