Can you fit multiple buttons in one grid cell in tkinter?

12,461

Yes you can. Put a frame inside the cell, and then you can put whatever you want inside the frame. Inside the frame you can use pack, place or grid since it is independent from the rest of the widgets.

For example:

import Tkinter as tk

root = tk.Tk()

l1 = tk.Label(root, text="hello")
l2 = tk.Label(root, text="world")
f1 = tk.Frame(root)
b1 = tk.Button(f1, text="One button")
b2 = tk.Button(f1, text="Another button")

l1.grid(row=0, column=0)
l2.grid(row=0, column=1)
f1.grid(row=1, column=1, sticky="nsew")

b1.pack(side="top")
b2.pack(side="top")

root.mainloop()
Share:
12,461

Related videos on Youtube

jnkjn
Author by

jnkjn

Updated on October 14, 2022

Comments

  • jnkjn
    jnkjn over 1 year

    I'm making a table, and the grid of the table is going to be filled with buttons, Is it possible to fit more than one button in a grid space?

    • jasonharper
      jasonharper almost 8 years
      Not directly, but you can put a Frame in that grid space, then put whatever you want in the Frame.
  • jnkjn
    jnkjn almost 8 years
    Thanks! This really helped a lot I really appreciate it.
  • jnkjn
    jnkjn almost 8 years
    Thanks for replying, your response really helped me out!