我的代码正在运行,我只是希望它看起来更容易。
2-12312 Bob Seesaw Active
4-1212 Jim Beene Off
我想把它展开以便于阅读(对于空间使用点数抱怨)
2-12312......Bob Seesaw.....Active
4-1212.......Jim Beene........ Off
我输入了特定于代码的
from tkinter import *
import pymysql as mdb
from tkinter import ttk
from tkinter import Listbox
-------
def viewroster():
rosterList.delete(0, "end")
dbi = mdb.connect("localhost", port=3306, user="user", passwd="pass", db="interactive_db")
cursor = dbi.cursor()
cursor.execute("""SELECT number, firstname, surname, available FROM active_roster""")
rows=cursor.fetchall()
dbi.close()
print (rows)
for results in rows:
rosterList.insert("end", results)
rosterList=Listbox(root, height=6,width=65)
rosterList.grid(row=2, column=0, rowspan=9, columnspan=4)
showButt=Button(root, text="Show All", width=12, command=viewroster)
showButt.grid(row=13, column=3)
2-12312 Bob Seesaw Active
4-1212 Jim Beene Off
我想把它展开以便于阅读(对于空间使用点数抱怨)
2-12312.....Bob Seesaw....Active
4-1212......Jim Beene ....Off
我没有错误
答案 0 :(得分:1)
您可以使用字符串格式
print( "| {:15s} | {:15s} | {:15s} |".format('2-12312', 'Bob', 'Seesaw Active') )
print( "| {:15s} | {:15s} | {:15s} |".format('4-1212', 'Jim', 'Beene Off') )
获取
| 2-12312 | Bob | Seesaw Active |
| 4-1212 | Jim | Beene Off |
请参阅第PyFormat.info页
但您必须使用monspaced
字体才能在Listbox
中正确显示它。
维基百科:Monospaced font