简体   繁体   中英

Why does the button size increase when I increase font size/change font type in?

self.button_decimal = Button(root, text=".", command=lambda: self.decimal(),
                             width="9", height="2", bg="steelBlue", font="Serif 12")

If I remove font="Serif 12" then everything is normal but when I add font="Serif 12" it does change the font size but it also increases/decreases the size of the button depending on what size you chose.

My questions are, 1.why does this happen? 2.How can I increase the font size and NOT the button size using the font="" argument?

1.why does this happen?

It happened because that's how they are designed to work. Buttons are sized relative to the font used by the button. 99.9% of the time this is the exact right thing to do. Without this, if you specify a large font, the text will be chopped off by the edges of the button.

2.How can I increase the font size and NOT the button size using the font="" argument?

You can't. See point #1.

Though, that's not 100% true. There are a couple options that work on some platforms (on OSX, for example, I think there is literally nothing you can do).

You can add an image to the button, in which case the width and height parameters will be treated as pixel values rather than a number of characters.

You can force a button to a specific size by providing constraints on the button via the geometry managers. I imagine this would be easiest with place since it has a width and a height attribute. However, it likely won't give you good results unless the font you switch to is nearly identical to the original font.

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