Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button sizes for my calculator Python Tkinter

Tags:

python

tkinter

enter image description here

I'm new to python and tkinter. I've been watching and studying a few tutorials over the past couple of days and my first project was a calculator.

Got a little confused somewhere down the line. If someone could please tell me how I can make the "0" button fill in the gap between the "." button. Also would like the "+/-" to fit evenly with the rest of the column.

I saw in another question similar to this a guy gave an answer as

button1.config( height = WHATEVER, width = WHATEVER2 )

Since I have my buttons placed in a grid, can I implement this and how?

bttn_0 = Button(calc, text = "0")
bttn_0["command"] = lambda: sum1.num_press(0)
bttn_0.grid(row = 5, column = 0, pady = 5)

enter image description here

like image 353
Andrew H Avatar asked Oct 05 '22 11:10

Andrew H


2 Answers

F3AR3DLEGEND is incorrect, you can get the desired effect using grid. You would need to use the columnspan keyword to make a widget span multiple columns, e.g.

bttn_0.grid(row = 5, column = 0, pady = 5, columnspan = 2)

For examples, see here.

like image 151
Junuxx Avatar answered Oct 10 '22 04:10

Junuxx


To get the zero to be next to the ".", set columnspan to 2. You might also want to set the column span of the top entry widget to 4 so that it fits exactly over the four columns of buttons (and set sticky as well, to get a perfect alignment).

You can't get the +/- button to fit evenly with the others since it's wider. You can, however, make the others fit the +/- button. If you use sticky="ew", the buttons will all expand in width to fill their columns (ie: they will "stick" to the east and west sides of their cell).

like image 38
Bryan Oakley Avatar answered Oct 10 '22 04:10

Bryan Oakley