CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

how can use persian fonts in FontManager

Open arefhr opened this issue 1 year ago • 4 comments

import customtkinter

app = customtkinter.CTk()

customtkinter.FontManager.load_font("B Traffic Bold_0.ttf") # Import the .ttf file by this method label = customtkinter.CTkLabel(app, text="سلام!", font=("B Traffic Bold_0",30)) label.grid(padx=70, pady=50)

app.mainloop()

font not changed in persian text.is there any way?

arefhr avatar Jan 29 '24 10:01 arefhr

Mind posting your version of font. I assume the unicode chars in the font you are trying to use are different than the one you have specified as text.

BhagyaJyoti22006 avatar Jan 29 '24 18:01 BhagyaJyoti22006

Mind posting your version of font. I assume the unicode chars in the font you are trying to use are different than the one you have specified as text.

So when i install this font in my windows,this is work. I want to be able to show it in the program without installing the font. Because you cannot manage the Windows fonts of the user that you use the applications.

arefhr avatar Jan 29 '24 18:01 arefhr

custom_font = tkinter.font.Font(family="your_font_name", size=14, file=path_font) now, you can use custom_font as required without installing the font.

BhagyaJyoti22006 avatar Jan 30 '24 20:01 BhagyaJyoti22006

This code worked for me:

from PIL import ImageFont

font_path = "assets/fonts/myfont.ttf"
font = ImageFont.truetype(font_path, size=20)
font_info = font.getname()
font_family = font_info[0]
ctk_font = customtkinter.CTkFont(family=font_family, size=20, weight="bold")
label = customtkinter.CTkLabel(frame, text=text, font=ctk_font)

ali-salavati avatar Feb 20 '24 08:02 ali-salavati