Posts: 60
Threads: 20
Joined: Oct 2016
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)
Posts: 1,144
Threads: 114
Joined: Sep 2019
Jan-26-2022, 05:19 PM
(This post was last modified: Jan-26-2022, 05:19 PM by menator01.)
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
Posts: 60
Threads: 20
Joined: Oct 2016
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)
Posts: 6,779
Threads: 20
Joined: Feb 2020
Jan-26-2022, 07:48 PM
(This post was last modified: Jan-26-2022, 08:00 PM by deanhystad.)
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()
Posts: 1,144
Threads: 114
Joined: Sep 2019
Jan-26-2022, 08:46 PM
(This post was last modified: Jan-26-2022, 08:46 PM by menator01.)
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
|