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)
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With