python tkinter rowspan not working properly

Posted January 4, 2021 2.7k views

so i was just making a gui for my calculator using tkinter in python and i wanted the clear button to be the size of 3 rows. so i entered rowspan=3. but this doesnt change the size of the clear button(in my code the button which says “cl” is the clear button) . pls check my code and help me. this is my code:

from tkinter import *
from tkinter import Button
root = Tk()

root.title("Basic Calculator")
entry = Entry(root, width=35, borderwidth=15)
entry.grid(row=0, column=0, columnspan=4, padx=10, pady=10)

b1 = Button(root,  text="1", padx=40, pady=20  )
b2 = Button(root,  text="2", padx=40, pady=20  )
b3 = Button(root,  text="3", padx=40, pady=20  )
b4 = Button(root,  text="4", padx=40, pady=20)
b5 = Button(root,  text="5", padx=40, pady=20  )
b6 = Button(root,  text="6", padx=40, pady=20  )
b7 = Button(root,  text="7", padx=40, pady=20  )
b8 = Button(root,  text="8", padx=40, pady=20 )
b9 = Button(root,  text="9", padx=40, pady=20 )
b0 = Button(root,  text="0", padx=40, pady=20 )
b_add = Button(root,  text="+", padx=40, pady=20)
b_sub = Button(root,  text="-", padx=40, pady=20)
b_div = Button(root,  text="/", padx=40, pady=20)
b_mul = Button(root,  text="✕", padx=40, pady=20, )
b_cl = Button(root,  text="Cl", padx=40, pady=20)
b_equal = Button(root,  text="=", padx=40, pady=20)

b1.grid(row=1, column=1)
b2.grid(row=1, column=2)
b3.grid(row=1, column=3)

b4.grid(row=2, column=1)
b5.grid(row=2, column=2)
b6.grid(row=2, column=3)

b7.grid(row=3, column=1)
b8.grid(row=3, column=2)
b9.grid(row=3, column=3)

b0.grid(row=4, column=1)

b_add.grid(row=4, column=2)
b_sub.grid(row=4, column=3)
b_mul.grid(row=5, column=2)
b_div.grid(row=5, column=3)
b_equal.grid(row=5, column=1)
b_cl.grid(row=6, rowspan=3,  column=1)

edited by KFSys

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi @anandu4115,

So I started troubleshooting the problem you’ve explained. So the RowSpan definition is

rowspan: This option will be used to tell how many rowwidgets are occupied and the default value is 1

Having said that, I think the code works as intended as I tested it out on my local machine as well. It makes the think looking into that guide as well Tkinter-gird that that’s the expected behavior.