Python Forum
[Tkinter] Trying to change font size w/o changing button size
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Trying to change font size w/o changing button size
I hope my formatting is proper.
My code:
from tkinter import *
from tkinter import font

root = Tk()
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)

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

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Trouble changing Font within tkinter frame title AnotherSam 1 597 Sep-30-2021, 05:57 PM
Last Post: menator01
  [Tkinter] changing and getting value through button niski1996 2 550 Aug-24-2021, 04:44 PM
Last Post: niski1996
  Tkinter menu font size -method to change tonycat 2 3,076 Oct-11-2020, 02:43 AM
Last Post: tonycat
  [tkinter] color change for hovering over button teacher 4 4,483 Jul-04-2020, 06:33 AM
Last Post: teacher
  [PyQt] Increase text size and change color based on temp pav1983 5 1,262 Jun-22-2020, 10:52 PM
Last Post: menator01
  TKINTER - Change font color for night or day Ayckinn 2 1,967 May-24-2020, 09:25 PM
Last Post: Ayckinn
  [PyQt] Qtableview adapte size to WBPYTHON 3 3,822 Mar-23-2020, 01:51 AM
Last Post: deanhystad
  [Tkinter] Treeview expand button size shamnadinn 8 3,965 Mar-08-2020, 12:02 PM
Last Post: shamnadinn
  Tkinter scaling windows conten to or with its size not working Detzi 5 2,123 Jan-12-2020, 12:42 PM
Last Post: Detzi
  [Tkinter] Scrollbar, Frame and size of Frame Maksim 2 6,044 Sep-30-2019, 07:30 AM
Last Post: Maksim

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020