格式化名单为列

问题描述 投票:0回答:1

我试图分裂,像这样我的专栏:

ID    Username    Password    Clearance    Class
1     foo         bar         Admin        True
etc   etc         etc         etc          etc

使用 “{0:> 8}”。格式(*ⅰ)方法

打印到控制台的工作原理,以及格式是好的,但是当我通过对我使用的显示搜索结果的弹出窗口传递文本,格式化更像是这样的:

ID    Username    Password    Clearance    Class
 1     foo    bar      Admin   False

这里是代码:

from tkinter.messagebox import showinfo

User_List = [["foo","bar","admin","true"],["fa","lo","user","false"]]

def Main():
    Display_Text_List = [["Index","Username","Password","Clearance","Class"]]
    for Count,Sub_List in enumerate(User_List):
        ID = str(Count+1)
        Username = Sub_List[0]
        Password = Sub_List[1]
        Clearance = Sub_List[2]
        Class = Sub_List[3]
        Display_Text_List.append([ID,Username,Password,Clearance,Class])
    Display_Text = Column_Format(Display_Text_List)
    print("Display_Text :\n")
    print(Display_Text)
    Popup_Show_Info(Display_Text)

def Popup_Show_Info(text):
    showinfo("Window", text)

def Column_Format(List):
    Text = ""
    print("LIST:",List)
    for i in List:
        print("i:",i)
        Text_Extension = "{0:>8} {1:>12} {2:>12} {3:>12} {4:>10}".format(*i)
        Text += Text_Extension+"\n"
    return Text

if __name__ == "__main__":
    Main()
python-3.x tkinter formatting
1个回答
0
投票

你需要一些选项添加到根。为了使您的工作例如,将其添加到顶部:

import tkinter
r = tkinter.Tk()
r.option_add('*Dialog.msg.font', 'Courier') # set the font for dialog boxes
r.option_add('*Dialog.msg.wrapLength', '800') # set the max width of dialog boxes
r.withdraw() # Hide the main window

在你真正的程序,你应该使用根窗口,而不是“R”。

© www.soinside.com 2019 - 2024. All rights reserved.