Python Forum
Unable to display Devanagari ligatures correctly in python tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to display Devanagari ligatures correctly in python tkinter
#1
Smile 
I am trying to display Devanagari (Hindi) text in python3 tkinter. I find that the display of text is incorrect in tkinter for all the widgets capable of holding text. The problem remains for any Truetype font with Unicode support. I have tried "Noto Sans", "Gargi", "Sankrit 2003" and some more Devanagari fonts.

This does not seem to be a problem with the font because -
i) I am getting correct display with any of the above fonts on ubuntu terminal (image attached)
ii) The text display is correct in html
iii) The problem appeared in python fpdf. But it got resolved when the flag set_text_shaping was set to TRUE.

The code is as under :

from tkinter import *
root = Tk()
print(TkVersion)
T = Text(root, height = 5, width = 52)
T.config(font =("Gargi", 20))
l = Label(root, text = "Errors in Devanagari display")
l.config(font =("Gargi", 20))
l.pack()
T.pack()
T.insert(END, "   संधिस्थापनके प्रयत्नका औचित्य बताना..")
root.main
I have attached images of correct display as well as erroneous display. Correct display is also seen in the code snippet above.

Any help towards resolving the issue would be thankfully received. If this has already been addressed / discussed in this forum, a link to that topic may please be provided. Thanks in advance.
       
Larz60+ write Nov-25-2024, 03:19 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button. Tags have been added for you this time.
Reply
#2
Devanagari is not one of the fonts in tkinter. To use Devanagari you need to import it as a custom font. There was a post about importing fonts in tkinter.

https://python-forum.io/thread-29667.html
Reply
#3
Importing the custom font from the ttf file has not resolved the issue. However, some users on another forum have mentioned that the code I attached has worked for them correctly on their platforms. I am unable to think of a way forward. Sad
Reply
#4
You can use custometkinter to load ttf fonts.
List of fonts that I got to work
  • Devanagari Plain9190 122439 PM.ttf
  • Ganga 1 Regular.ttf
  • Kruti Dev 714 Normal.ttf
  • Maiya Regular.ttf
  • Manishau Regular.ttf

import customtkinter as tk

app = tk.CTk()
app.configure(padx=10, pady=8)
tk.FontManager.load_font('Maiya Regular.ttf')

label = tk.CTkLabel(app, text='Hello World!', font=('Maiya', 48))
label.pack()

app.mainloop()
Gribouillis likes this post

Attached Files

Thumbnail(s)
   
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply
#5
AFAIK, fonttools https://pypi.org/project/fonttools/ is required to use additional fonts in Python. There is a way to do this using PIL and a canvas widget https://www.devgem.io/posts/displaying-d...mon-issues
Gribouillis likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display results from terminal window onto tkinter. buttercup 0 4,466 Jul-21-2020, 04:41 AM
Last Post: buttercup
  [Tkinter] How to compare two variables correctly in tkinter scratchmyhead 2 4,790 May-10-2020, 08:04 PM
Last Post: scratchmyhead
  [Tkinter] Problems to display Web Scraping values in Tkinter Lucas_Ribeiro 0 2,054 May-07-2020, 12:36 AM
Last Post: Lucas_Ribeiro
  Tkinter:Unable to bind and unbind function with a button shallanq 2 6,146 Mar-28-2020, 02:05 AM
Last Post: joe_momma
  Unable fetch fucntion data in class in tkinter jenkins43 2 4,964 Nov-30-2019, 09:47 PM
Last Post: jenkins43
  Unable to put background image on Tkinter Frame jenkins43 2 9,813 Nov-27-2019, 11:38 AM
Last Post: jenkins43
  tkInter and Pillow don't display any images in GUIs - program gives errors instead SomeRandomGuy 9 17,347 Oct-29-2019, 02:57 PM
Last Post: SomeRandomGuy
  Unable to update or refresh label text in tkinter jenkins43 3 8,737 Jul-24-2019, 02:09 PM
Last Post: Friend
  Display and update the label text which display the serial value jenkins43 5 11,124 Feb-04-2019, 04:36 AM
Last Post: Larz60+
  Display more than one button in GUI to display MPU6000 Sensor readings barry76 4 5,141 Jan-05-2019, 01:48 PM
Last Post: wuf

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020