我试图缩小wip计算器上按钮之间的间距,但当我试图通过更改字体大小来更改输入字段的高度时,我制作的所有按钮都会进一步分开,我如何解决这个问题?

这是我的代码:

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")) | -font=("Arial 24)是导致问题的原因,但我不知道如何修复它,同时仍然有一个更大/更高的输入字段

推荐答案

我发现了一些可能与你需要的东西有关的东西:

Remove space between buttons in tkinter

干杯

Python相关问答推荐

在有限数量的唯一字母的长字符串中,找到包含重复不超过k次的所有唯一字母的最长子字符串

Odoo onchange for invoice_Status of sale事件.订单未触发

Flask:如何在完整路由代码执行之前返回验证

两极:如何分割一个大 pyramid 并并行保存每个

仅对matplotlib的条标签中的一个条标签应用不同的格式

给定数据点,制定它们的关系

从今天起的future 12个月内使用Python迭代

在使用Guouti包的Python中运行MPP模型时内存不足

在Python中为变量的缺失值创建虚拟值

Python 3.12中的通用[T]类方法隐式类型检索

线性模型PanelOLS和statmodels OLS之间的区别

比较两个数据帧并并排附加结果(获取性能警告)

Pandas实际上如何对基于自定义的索引(integer和非integer)执行索引

运行终端命令时出现问题:pip start anonymous"

发生异常:TclMessage命令名称无效.!listbox"

如何使用表达式将字符串解压缩到Polars DataFrame中的多个列中?

什么是最好的方法来切割一个相框到一个面具的第一个实例?

为什么if2/if3会提供两种不同的输出?

Pandas:填充行并删除重复项,但保留不同的值

在Python中从嵌套的for循环中获取插值