Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python tkinter Listbox widget: unicode text with ' char get jumbled

Using python 2.7 and Tkinter
I have a Listbox widget and a Text widget showing the same text.
In the Text widget everything looks correct. But in the Listbox the font is different and where there are ' chars the text gets to be jumbled.

How can the Listbox text be shown properly ?

Here's a screenshot of the Text widget:
Text widget screenshot
And Here's one for the Listbox widget:
Listbox widget screenshot

The listbox creation code is:

self.r_list = Listbox(self.frame, selectmode='multiple', exportselection=0)
for item in self.all:
    self.r_list.insert(END, item)

and the text creation code is:

self.r_text = Text(self.frame)
self.r_text.insert(END, "\n".join(self.all))
self.r_text.config(state=DISABLED)

Where the self.all var is:

[u'\u05d0\u05dc\u05d5\u05e8\u05d4', u"\u05e6'\u05d5\u05e4 \u05e6'\u05d5\u05e4"]
like image 825
Eran Avatar asked Mar 08 '26 00:03

Eran


1 Answers

Solved by setting font in the listbox

self.r_list = Listbox(self.frame, selectmode='multiple', exportselection=0, font=('Tahoma', 8))

It's not just the Tahoma font that works, I guess it's mostly an issue of the default font.

like image 110
Eran Avatar answered Mar 10 '26 15:03

Eran



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!