0

I am trying to do what the Title says, Configure the Tkinter message so that each tuple in WL_ratios has its own line without being surrounded in brackets. Creating more messages is not an option as the length of WL_ratios can vary, so i have to only use the one.

#(below) is in the __init__ of the class
self.Leaderboardtext = Message(self.LeaderboardFrame,text="",width=100)
self.Leaderboardtext.pack() 

#this (below) is in another function in the same class.
WL_ratios = [["james",3]["harrison",2]["jo",1]]
self.Leaderboardtext.configure(text="Leaderboard: {0}".format(WL_ratios))

So far the width=100 is the only thing that is allowing me to get text onto a new line. However this still isnt working because each tuple varies in length so some tuples spread across two lines which isnt what i want. I know you could limit each line by how number of characters but again the tuples vary in character length so i dont think that is an option. Does anyone have any suggestions that could work?

snaktastic
  • 43
  • 1
  • 1
  • 6
  • Have you tried using a textvariable rather than a simple string ? – ldoe Feb 03 '19 at 18:02
  • @LilianBordeau sorry, in reference to what? – snaktastic Feb 03 '19 at 18:08
  • 1
    Sorry I misunderstood your problem, textvariable won't help. Since you are using the Message widget, you can add the breaking line character '\n' between your tuples. This will add a new line for each of them. – ldoe Feb 03 '19 at 18:09
  • But this is bad practice anyway. The fact that WL_ratios length can vary should not restrain you from creating multiples message widgets. If you are iterating over WL_ratios, you will go through all of them anyway. If you want to create a proper leaderboard table, with columns and rows, you can use the [treeview widget](https://docs.python.org/3/library/tkinter.ttk.html#tkinter.ttk.Treeview). – ldoe Feb 03 '19 at 18:16
  • Have you tried explicitly converting the data to lines separated by newlines before passing them to the widget? – Bryan Oakley Feb 03 '19 at 18:27
  • @BryanOakley Ive just done that and its done the job – snaktastic Feb 03 '19 at 18:42
  • @LilianBordeau What im doing isnt too complicated just a very basic leaderboard is going to work, but ill keep that link in mind in the future. thanks. – snaktastic Feb 03 '19 at 18:42

1 Answers1

2

Just convert each tuple into a string, and add \n there, and that should do it. Alternatively, you could call each value in the tuple separately, and add \n there.

Random Channel
  • 1,134
  • 10
  • 22
  • When taken literally, "just add `\n` inbetween your tuples" won't work. You need to convert the tuples to a string, and insert the newlines between each string. You might want to be a bit more explicit about what you're suggesting. – Bryan Oakley Feb 03 '19 at 18:28