在Mac上调整tkinter中的按钮大小

时间:2015-01-18 04:16:51

标签: python button tkinter

我还是tkinter的新手,注意到当我尝试使用

来增加按钮的大小时
 button.config(height=20, width=50)

根本没用。它只是紫罗兰色背景中的一个巨大的白色空间区域,然后是白色空间中间的按钮。如果我点击了白色空间内的任何地方,它就可以工作并完成它的命令。

以下是代码:

from tkinter import *

root = Tk()
def cheese():
    print ('hi')
logo = PhotoImage('../Desktop/logothing.gif')
explanation = """Flaming Arrows whizz over your hair, War rages around you. Suddenly,
it charges into you. A 8 foot tall mechanical beast the enemy have been training for war.
You have no chance but to fight it. You swing your sword as hard as you can...Only to
leave a minor dent on it's armor. With one blow from its club, you fall unconscious."""

w2 = Label(root, justify=LEFT, text=explanation, image = logo, 
           compound = CENTER, fg="blue", bg= "Violet", 
        font="ComicSansMS 32 bold",padx=1000, pady=1000).pack(side='left')
w1 = Button(root, text = 'Hello',command = cheese, padx=10)
w1.config(height=20, width = 50)
w1.place(x=500, y=500)

2 个答案:

答案 0 :(得分:1)

我已经在我的Mac上进行了测试,似乎你无法调整按钮的高度(它就像pady一样),但只是宽度。事实上,如果你将按钮的高度降低到1,你会得到类似的结果:

enter image description here

我能看到的唯一解决方法是增加字体的大小。 如果您使用pady,则只会垂直增加包含按钮的白框。

这可能是一个特定于平台的问题,正如Bryan Oakley在评论中提到的那样。

答案 1 :(得分:0)

增加字体大小不起作用。这是我尝试时遇到的,因为遇到同样的问题。

font going off the button