I am trying to reduce the spacing between buttons on a wip calculator, but when I try to change the height of the Entry field by changing the font size, all the buttons that I have made move further apart, how can I fix this issue?
Here is my code:
from tkinter import *
import math
window = Tk()
window.title("Calculator")
window.geometry("250x370")
expression = ""
equation = StringVar()
field = Entry(window,width=35, bd=0,textvariable=equation,font=("Arial 24"))
field.grid(columnspan=4,padx=5,pady=10)
#-------------------------------------------------------
def press(num):
global expression
expression=expression str(num)
equation.set(expression)
def calculate():
try:
global expression
result= str(eval(expression))
expression=str(result)
equation.set(expression)
except:
expression=""
equation.set("error")
def clearer():
global expression
expression=""
equation.set("")
#-------------------------------buttons------------------------------------
button1 = Button(window,text="1",command=lambda:press(1),height=4,width=7)
button1.grid(row=2,column=0)
button2 = Button(window,text="2",command=lambda:press(2),height=4,width=7)
button2.grid(row=2,column=1)
button3 = Button(window,text="3",command=lambda:press(3),height=4,width=7)
button3.grid(row=2,column=2)
button4 = Button(window,text="4",command=lambda:press(4),height=4,width=7)
button4.grid(row=3,column=0)
button5 = Button(window,text="5",command=lambda:press(5),height=4,width=7,)
button5.grid(row=3,column=1)
button6 = Button(window,text="6",command=lambda:press(6),height=4,width=7)
button6.grid(row=3,column=2)
button7 = Button(window,text="7",command=lambda:press(7),height=4,width=7)
button7.grid(row=4,column=0)
button8 = Button(window,text="8",command=lambda:press(8),height=4,width=7)
button8.grid(row=4,column=1)
button9 = Button(window,text="9",command=lambda:press(9),height=4,width=7)
button9.grid(row=4,column=2)
button0 = Button(window,text="0",command=lambda:press(0),height=4,width=7)
button0.grid(row=5,column=0)
clear = Button(window,text="Clear",command=clearer,height=4,width=7)
clear.grid(row=5,column=1)
equals = Button(window,text="=",command=calculate,height=4,width=7)
equals.grid(row=5,column=2)
plus = Button(window,text=" ",command=lambda:press(" "),height=4,width=7)
plus.grid(row=2,column=3)
minus = Button(window,text="-",command=lambda:press("-"),height=4,width=7)
minus.grid(row=3,column=3)
multiply = Button(window,text="*",command=lambda:press("*"),height=4,width=7)
multiply.grid(row=4,column=3)
divide = Button(window,text="/",command=lambda:press("/"),height=4,width=7)
divide.grid(row=5,column=3)
window.mainloop()
field = Entry(window,width=35, bd=0,textvariable=equation,font=("Arial 24"))
| the -font=("Arial 24)
is what is causing the problem but I have no idea how to fix it while still having a larger/taller Entry field
CodePudding user response:
I found something that has maybe something to do with what you need:
Remove space between buttons in tkinter
Cheers