简体   繁体   English

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

[英]Resizing a Button in tkinter on a Mac

I'm still new to tkinter , and noticed that when I tried to increase the size of a button using 我还是tkinter新手,并注意到当我尝试使用来增加按钮的大小时

 button.config(height=20, width=50)

It didn't work at all. 它根本没有用。 It was just a huge area of white space in the violet background, and then the button in the middle of the white space. 在紫罗兰色的背景下,这只是空白区域的巨大区域,在空白区域的中间是按钮。 If I clicked anywhere within the white space though, it worked and did its command. 但是,如果我单击空白区域内的任何地方,它将起作用并执行其命令。

Here's the code: 这是代码:

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)

I have tested on my Mac and it seems that you cannot resize the height of the button (it works as if it was the pady ), but just the width. 我已经在Mac上进行了测试,看来您无法调整按钮的高度(它的工作原理就像是pady ),只能调整宽度。 In fact, if you decrease the height of your button to 1, you will have something like this: 实际上,如果将按钮的高度减小到1,您将得到以下内容:

在此处输入图片说明

The only workaround I can see is to increase the size of the font. 我可以看到的唯一解决方法是增加字体的大小。 If you use pady , you will just increase vertically the white box containing the button. 如果使用pady ,则将垂直增加包含按钮的白框。

This might be a platform specific problem, as Bryan Oakley mentioned in a comment. 正如Bryan Oakley在评论中提到的那样,这可能是特定于平台的问题。

Increasing the font size doesn't work. 增加字体大小不起作用。 This is what I got when I tried it because I'm experiencing the same problem. 这是我尝试时遇到的问题,因为遇到同样的问题。

font going off the button 字体关闭按钮

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

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