Python Forum

Full Version: Trying to change font size w/o changing button size
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I hope my formatting is proper.
My code:
from tkinter import *
from tkinter import font

root = Tk()
root.geometry('500x500')
root.title('Tkinter Frame Test')
myFont = font.Font(family = 'Helvetica', size = 20)

frame1 = Frame(root, bg='green')
frame1.pack(expand=True, fill=BOTH)

frame2 = Frame(frame1, width = 20, height = 20)
frame2.pack(expand = False)

button1 = Button(frame2, text='Grrrrr', font = myFont)
button1.pack()

root.mainloop()
Made this little tkinter test code, i make tiny programs for testing so i don't screw up my main program, and what i am trying to do is get a button where i can change the font size of the button text without changing the button size. I know width= and height= are specified in character width which is why the button size gets bigger when the font get bigger. My understanding is that to make this work, i need to put the button in its own frame as the frame is specified in pixels and i just have to set the button to expand=True and fill=BOTH. I just can't get it to work. am i wrong in my thinking? am i coding it wrong? I made frame1 the root frame, frame2 the button frame inside of frame1 to hold my button. no matter what i do, when i change font size, button size changes even if i try to "freeze" frame1 by expand=False.
add width and height values to button to force desired size.
(Aug-04-2020, 11:23 AM)Larz60+ Wrote: [ -> ]add width and height values to button to force desired size.

when i do that, the button becomes almost as large as the window. the root.geometry('500x500') is in pixels , the button is still 20 characters high and wide, not sure what 20/20 on frame is is, doesnt seem like pixels or characters. i hope i am explaining this correctly.
if you use the variables, you control the width and height, it will become whatever size you specify
I am talking about width and height in the Button widget definition:
button1 = Button(frame2, text='Grrrrr', font = myFont, width=100, height=25)
I just guessed at sizes, you will have to adjust