擅长:python、mysql、java
<p>不如asongtoruin但是</p>
<pre><code>from Tkinter import *
master = Tk()
info=[ ['sue', 1, 'Argentina', 'Bsc'],
['peggy-sue', 17, 'U.K.', 'Bsc'],
['susie', 234, 'France', 'BA']
]
heads = ["Name","id","Nationality","Qual"]
listbox = Listbox(master, width=60)
listbox.pack()
fixedlen = 10
listbox.insert(END, ("{:<15s}"+(fixedlen-len(heads[0]))*" " +"{:>5s}"+(fixedlen-len(heads[1]))*" " +"{:<25s}"+(fixedlen-len(heads[2]))*" " +"{:<5s}").format(heads[0],heads[1],heads[2],heads[3]) )
for i in range(len(info)):
item = ("{:<15s}"+(fixedlen-len(str(info[i][0])))*" " +"{:>5d}"+(fixedlen-len(str(info[i][1])))*" " +"{:<25s}"+(fixedlen-len(str(info[i][2])))*" " +"{:<5s}").format(info[i][0],info[i][1],info[i][2],info[i][3])
print item # Gives nicely formatted lines
listbox.insert(END, item) #Lines are not nicely formatted in listbox
mainloop()
</code></pre>