Printing trees - Is there a way to ensure text in Kivy labels is aligned perfectly?

oh93

I'm trying to develop a Kivy desktop app which needs to display trees in labels.

The tree is just a string that looks something like this:

"   ┌ 3 \n   │\n 1 ┤                  ┌ 2 \n   └─────────────── 4 ┤\n                      └ 5 "

This works perfectly when operating inside the terminal, and the tree is aligned correctly as below.

Tree in terminal

However, when putting this string inside a Kivy label, it does not align correctly (see below).

Tree in Kivy label

I'm thinking there is an issue with the dimensions of the text not being the same as they are in the terminal. However, I have had no luck adjusting the properties of the label, the text size, the font or anything else. The problem always seems to persist.

The default font would not even display the tree branches. I set the font_name to "DejaVuSans.ttf", which at least renders the branches, but they are still not aligned.

I'm at my wit's end and no searches are returning any relevant information. Any help with fixing this annoying issue would be greatly appreciated.

Also, if there is a cleverer way to display trees in a Kivy app that would bypass this issue entirely, that would be even better!

John Anderson

If you use the FreeMono font and adjust the label text to:

"    ┌ 3 \n    │\n 1 ┤                               ┌ 2 \n    └─────────────── 4 ┤\n                                    └ 5 "

it seems to work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Image and text isnt aligned perfectly

Labels are not aligned properly with text box

Text Labels in kivy are not being updated

Flutter: Ensure Text is perfectly centred when there are more items on one side?

Right Column not perfectly aligned

Kivy text markup printing its own syntax

Problem when trying to create a left-aligned text using kivy

Labels not aligned on top left side above text inputs

How can I make the text of my button been perfectly aligned vertically?

Can anyone hint at a way to recall my iterated labels in kivy?

Why does the kivy labels text show out of the label?

React Native ScrollView not paginating in a perfectly aligned manner

Is there a cleaner/simpler way to achieve 2 aligned columns, text/image?

html & css - Images and Text aligned in the right way not working

x-axis text labels not aligned with bars in D3.js

Printing a right-aligned "#" staircase

Adding labels programmatically, aligned with labels from Storyboard

Printing mailing labels

Printing diverse .jpg labels

Printing Labels Programmatically in Access

histogram: printing group labels

JTable column labels not printing

Updating multiple Labels with kivy

Kivy - Labels, Buttons and Layouts

Is there a way to make the text color in a TextInput in kivy to be dependent on the background?

Is there a way to move a kivy slider with button's and text box?

Best way to center title text in a div but have the rest of the text left aligned?

Text not printing

Foundation 6 masonry effect with perfectly aligned outer edges?