0

Here is my question:

Im adding a string to a listbox created using two other strings. This is all taking place in a loop. Simplified code looks like this :

 a = "some string"
 b = "some other string"
 mystring = a.ljust(Some_Number) + " " + b
 print(mystring)
 myListbox.insert(myindex,mystring)

I would like to have something that looks like this in my listbox :

"dfasdfsdf             dfsd"
"sdfsdf                adfsdsfsaf"
"sd                    adfsdf"

Basically the second string always starting at the same index(Some_number + " "). When I print it in the command prompt i get exactly what i want but in the Listbox the spacing is not the same and all over the place. Any thoughts why this happens and how to fix it?

Thanks for any help.

4
  • 1
    Is your listbox using a fixed width font? Commented Nov 29, 2016 at 21:52
  • I'm not sure, that is likely the problem, what fonts are fixed lenght and how can i set them? Commented Nov 29, 2016 at 21:54
  • 1
    You will need a fixed width font if you're trying to align your data in columns. Commented Nov 29, 2016 at 21:55
  • 1
    You can set the font with the font argument when creating the listbox, I don't know your platform but Courier is fixed width. Commented Nov 29, 2016 at 22:02

1 Answer 1

1
mylistbox=tk.Listbox(myframe,font="TkFixedFont")

Hey guys the line of code above when initializing the listbox fixed my problem it was indeed a fixed width font problem, bit of a silly question... Thanks for all the help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.