Skip to content
loading...

How to use custom font with Python Tkinter Canvas?

calin92540842 profile image PDS OWNER CALIN (Calin Baenen) twitter logo github logo ・1 min read  

RuntDeale (5 Part Series)

1) My Undertale fan-game (RuntDeale)'s logo 2) How to stop image stretching/smoothing (anti-aliasing) in Chrome canvas 3) (RuntDeale website setup) -- RuntDeale talk 4) How to (up || down)scale a tkinter PhotoImage? 5) How to use custom font with Python Tkinter Canvas?

How can I set I custom font, currently I know how to set a font,
let's say I have a Canvas element (ctx).

Now, I to switch the font I do:

fontName = "Arial"
fontSize = 10

ctx.itemconfig(font=(fontName,fontSize))



but let's say I have a .ttf file, how would I go about importing a font from a .ttf file, in the same, or child folder, in python?

Thanks!
Cheers!
twitter logo DISCUSS
Discussion
markdown guide
Classic DEV Post from Jan 28 '19

8 Jenkins plugins I can't live without

These are some of the Jenkins plugins I use the most and which without I would have my work a lot harder

PDS OWNER CALIN (Calin Baenen) profile image
I am a 13 (as of Oct 30 of 2019) yr/o developer (I have been developing mini-projects for 4, years now, since I was 9), who makes projects in languages like: Java, HTML, Python 3, JS, CSS, and C#.