Python Forum
how to change font size - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: how to change font size (/thread-36193.html)



how to change font size - barryjo - Jan-26-2022

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)



RE: how to change font size - menator01 - Jan-26-2022

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()



RE: how to change font size - barryjo - Jan-26-2022

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) 



RE: how to change font size - deanhystad - Jan-26-2022

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()



RE: how to change font size - menator01 - Jan-26-2022

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()