繁体   English   中英

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

[英]Resizing a Button in tkinter on a Mac

我还是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)

我已经在Mac上进行了测试,看来您无法调整按钮的高度(它的工作原理就像是pady ),只能调整宽度。 实际上,如果将按钮的高度减小到1,您将得到以下内容:

在此处输入图片说明

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

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

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

字体关闭按钮

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM