Truly custom font in Tkinter

后端 未结 6 1197
悲哀的现实
悲哀的现实 2020-11-29 10:28

I am making an interface in Tkinter and I need to have custom fonts. Not just, say, Helvetica at a certain size or whatever, but fonts other than what would normally be ava

6条回答
  •  难免孤独
    2020-11-29 10:46

    for linux, I was able to install the otf font file I had into the system fonts directory:

    mkdir /usr/share/fonts/opentype/my_fonts_name
    cp ~/Downloads/my_fonts_name.otf /usr/share/fonts/opentype/my_fonts_name/
    

    I found this home directory worked, and ended up using it instead:

    mkdir ~/.fonts/
    cp ~/Downloads/my_fonts_name.otf ~/.fonts/
    

    in either case, then I could load it using a string of the font-name (as all the tkinter docs show):

    # unshown code
    self.canvas = tk.Canvas(self.data_frame, background="black")
    self.canvas.create_text(event.x, event.y, text=t, tags='clicks', 
                            fill='firebrick1',
                            font=("My Fonts Name", 22))
    

提交回复
热议问题