Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Segoe font in a Tkinter label?

I am trying to give a modern look to my tkinter GUI. Here is the syntax I am using without any luck. Any help will be greatly helpful!

from Tkinter import *
my_font=("Segoe UI", 20, "bold")

root =Tk()
root.geometry("800x480)
Label=(root, text="my label", font = my_font).place(x=320, y=10)

root.mainloop()
like image 477
Veejay Avatar asked Dec 05 '25 18:12

Veejay


1 Answers

My answer is going to address two points

  1. which font families you can use immediately in tkinter and
  2. what you can do if the family you'd like to use is not immediately available.

Available Font Families

Python 2

>>> from Tkinter import Tk
>>> from tkFont import families
>>> Tk(); available = families()   ### Tk() is needed to have a running tcl interpreter
<Tkinter.Tk instance at 0x7f977bcbfb90>
>>> len(available)
3011

Python 3

>>> from tkinter import Tk
>>> from tkinter.font import families
>>> Tk() ; available = families()
<tkinter.Tk object .>
>>> len(available)
68

at this point you can examine the fonts that are available printing, sorting slicing etc the contents of available — nb the names listed are the names that you have to use in the font definition tuple as in your example code.

Adding Fonts

As far as I can tell, this could be done in general as a system dependent (complicated) hack and the only published one is ONLY for Windows.

Said hack (I'll repeat: Windows only) is reported in this SO answer.

I don't know how to proceed in general.


Footnote

3011 font families for Python 2 and 68 for Python 3? yes, Python 2 is the system Python installed by apt on my Debian pc, while Python 3 is Anaconda's one and sees just the fonts that Anaconda installed in its private tree.

like image 145
gboffi Avatar answered Dec 07 '25 13:12

gboffi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!