Python Forum
how to change font size
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to change font size
#1
I have a button defined below.

What does 40 mean? Is there a 40 font?
How do I change the font size. i.e. maker it larger or smaller?
buttonGetAzEl=tk.Button(frame, text="GetAzEl", font = 40, command = GetAzEl)
buttonGetAzEl.place(relx = 0.28, rely = 0.07, relheight=0.05, relwidth=0.20)
Reply
#2
import tkinter as tk

root = tk.Tk()
root['padx'] = 8
root['pady'] = 4
tk.Label(root, text='Button with font and a size of10').pack()
btn = tk.Button(root, text='Button 1', font=('tahoma 10'))
btn.pack()

tk.Label(root, text='Button with font and size of 40', font=('verdana 20')).pack()
btn2 = tk.Button(root, text='Button 2', font=('verdana 40'))
btn2.pack()

tk.Label(root, text='Button with font and size of 20 and bold', font=('times 20 bold')).pack()
btn3 = tk.Button(root, text='Button 3', font=('times 20 bold'))
btn3.pack()
root.mainloop()
BashBedlam likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
This helps but what does the 40 mean"
does it mean size 40 for a default font? If I change 40 to 20 nothing happens. ???

However, I Find I can change the font merely by naming the font and size as below.
This seems simple.

buttonGetAzEl=tk.Button(frame, text="GetAzEl", font = ('helvetica','30') , command = GetAzEl) 
Reply
#4
You need to specify enough of a description that tkinter can create a font object. Size is not enough.
times is a True Type font which is resizeable.
import tkinter as tk

root = tk.Tk()
root['padx'] = 10
root['pady'] = 10
for size in range(8, 40, 2):
    tk.Label(root, text=f"This is font size {size}", font=(f"times {size}")).pack()
root.mainloop()
Reply
#5
To see the tkinter fonts you can do

import tkinter as tk
from tkinter import font
root = tk.Tk()
families = font.families()

tk.Label(root, text=f'tkinter has {len(families)} fonts available.', font=('serif', 14, 'bold')).pack(side='top')

scrollbar = tk.Scrollbar(root)
scrollbar.pack(side='right', fill='y')

text = tk.Text(root, width=75, yscrollcommand=scrollbar.set)
for font_name in families:
    text.insert(tk.END, f'{font_name}\n')
scrollbar.config(command=text.yview)
text.pack(side='top', fill='x')

root.mainloop()
BashBedlam likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter menu font size -method to change tonycat 2 7,862 Oct-11-2020, 02:43 AM
Last Post: tonycat
  [Tkinter] Trying to change font size w/o changing button size python63 3 9,878 Aug-05-2020, 01:04 AM
Last Post: Larz60+
  [PyQt] Increase text size and change color based on temp pav1983 5 3,195 Jun-22-2020, 10:52 PM
Last Post: menator01
  TKINTER - Change font color for night or day Ayckinn 2 3,887 May-24-2020, 09:25 PM
Last Post: Ayckinn
  [WxPython] How to change font color of SetHint or SetDescriptiveText? anistorian 5 3,918 Jun-19-2019, 05:30 PM
Last Post: Yoriz
  PyGtk3 why is Locale Folder Size Half of Module Size ? harun2525 1 3,632 Mar-09-2017, 03:46 AM
Last Post: Analyser

Forum Jump:

User Panel Messages

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