使用place方法时如何在tkinter中增加字体大小而不增加窗口小部件大小

时间:2019-06-02 04:38:31

标签: tkinter

我是。我想在tkinter中使用一个小型计算器应用程序,但我想使字体看起来更大而不使按钮变大。按钮应具有足够的大小,以使文本能够在其中占据。我尝试了下面的代码,但无法正常工作。

我看到了发布的解决方案 how increase font size in text widget?

但是由于它使用pack方法,所以不能解决我的问题。 我想使用.place()方法



from tkinter import *


mainwindow=Tk()
mainwindow.title("Calculator")
mainwindow.geometry('400x300+500+200')
mainwindow.config(bg='green')

inp=Text(mainwindow ,width=25,height=2)
inp.place(x=20,y=45)


k=30

w=3
h=2


o1=Button(mainwindow,text='1',width=w,height=h)
o1.place(x=k+10,y=100)
o2=Button(mainwindow,text='2',width=w,height=h)
o2.place(x=k+65,y=100)
o3=Button(mainwindow,text='3',width=w,height=h)
o3.place(x=k+120,y=100)
o4=Button(mainwindow,text='4',width=w,height=h)
o4.place(x=k+10,y=150)
o5=Button(mainwindow,text='5',width=w,height=h)
o5.place(x=k+65,y=150)
o6=Button(mainwindow,text='6',width=w,height=h)
o6.place(x=k+120,y=150)
o7=Button(mainwindow,text='7',width=w,height=h)
o7.place(x=k+10,y=200)
o8=Button(mainwindow,text='8',width=w,height=h)
o8.place(x=k+65,y=200)
o9=Button(mainwindow,text='9',width=w,height=h)
o9.place(x=k+120,y=200)
o0=Button(mainwindow,text='0',width=w,height=h)
o0.place(x=k+65,y=250)

plus=Button(mainwindow,text='+',width=1,height=1,font=('times new roman',60,'bold'))
plus.propagate(False)
plus.place(x=k+200,y=100)
plus.pack_configure(padx=100)
minus=Button(mainwindow,text='-',width=w,height=h)
minus.place(x=k+200,y=150)
mul=Button(mainwindow,text='X',width=w,height=h)
mul.place(x=k+200,y=200)
div=Button(mainwindow,text='/',width=w,height=h)
div.place(x=k+200,y=250)








mainwindow.mainloop()





按钮上的所有文本都应足够大,例如在“井字游戏”中,其“ X”和“ 0”

0 个答案:

没有答案