Soichiro
Soichiro

Reputation: 91

Python Tkinter listbox alignment

What is the best way to align a listbox as the following?

   1     7.56
   2   115.07
 ...
  10   789.00
 ...
 100     0.01
 ...
1000    17.77

Could someone please explain to me how to achieve this alignment?

Upvotes: 1

Views: 5160

Answers (1)

Soichiro
Soichiro

Reputation: 91

After working all night, I came up with this solution.

if data < 10:
    self.listbox.insert(END, "   {:>}    {:>8}".format(n, data))
elif data < 100:
    self.listbox.insert(END, "   {:>}   {:>8}".format(n, data))
elif data < 1000:
    self.listbox.insert(END, "   {:>}  {:>8}".format(n, data))
else:
    self.listbox.insert(END, "   {:>} {:>8}".format(n, data))

By the way, my listbox has

self.listbox.configure(justify=RIGHT)

Upvotes: 2

Related Questions