简体   繁体   中英

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

 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. In fact, if you decrease the height of your button to 1, you will have something like this:

在此处输入图片说明

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.

This might be a platform specific problem, as Bryan Oakley mentioned in a comment.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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