1

I'm trying to write a music program that would display Chordpro files in python. Similar to this image, I want the chords, comments, and lyrics to each have different colours. I've tried these widgets:

I tried separating chords, comments and lyrics into multiple strings that could overlap on a canvas (with a different colour for each string) to make the full song, but sadly whitespace overrides previously rendered text, so I could only see the last layer.

Label/Message doesn't have functionality for multiple colours unless make a label for each line, which is very tedious, considering I want the font size to be adjustable too.

Text is editable, which I don't want.

Is there some kind of module or other tkinter widget that would allow separately coloured lines?

Pomegranate
  • 42
  • 1
  • 7
  • 1
    You can make the Text widget as read_only by configure it with `state=disabled`. Note you need to set the state to `normal`by inserting something. To get the idea: https://stackoverflow.com/a/63412737/13629335 – Thingamabobs Aug 27 '20 at 19:23
  • I don't understand your comment about whitespace overriding previously rendered text. I don't see that when I write one word on top of another. Any place in the second string that has whitespace, I see the characters underneath. As for the Text widget, it has the abillity to be made read-only. – Bryan Oakley Aug 27 '20 at 20:57
  • To clarify, when you say "lines" do you mean "lines of text"? When talking about the Canvas, it has the ability to draw actual lines. – Bryan Oakley Aug 27 '20 at 20:58
  • @BryanOakley I probably messed something up with the canvas then. With lines I meant lines of text. But it doesn't matter anymore, I made it work by using the Text widget :) – Pomegranate Aug 28 '20 at 10:48

1 Answers1

0

Just draw the separate lines at different y positions (heights) on the canvas. It's the first two parameters of the create_text() function. E.g.

self.canvas = Canvas(root, width=800, height=650, bg = '#afeeee')
self.canvas.create_text(100,10,fill="darkblue",font="Times 20 italic bold",
                    text="Greensleeves are my...")

So here, change 10 to the line position you want etc. Code copied from Python: how to add text inside a canvas?

Paul Sumpner
  • 447
  • 7
  • 8