简体   繁体   English

Tkinter 文本框看起来与终端打印不一样

[英]Tkinter textbox does not look the same as terminal print

My TKinter textbox formats weirdly and does not look like the command text.我的 TKinter 文本框格式很奇怪,看起来不像命令文本。 I have a pandas db and it inserts it weirdly.我有一个 pandas db,它奇怪地插入了它。 Any ideas what I'm doing wrong?任何想法我做错了什么?


        table = PrettyTable()

        # Set the column names
        table.field_names = df.columns.tolist()
        for row in df.itertuples(index=False):
            table.add_row(row)
        textbox_string = str(table)
        #df.columns = ['owner ', 'project ', 'branch ', 'updated ', 'insertions ', 'deletions ']
        #df.style.set_properties(subset=pd.IndexSlice[:, :], **{'width': '50px'})
       
        #textbox_string = df.to_string(index=True, justify='center')
        print(textbox_string)
        root.textbox.configure(font=("Roboto", 14))
        root.textbox.insert("0.0",textbox_string)

Console text the console text Here's how the GUI shows it TKinter textbox text Console text the console text这是 GUI 显示它的方式 TKinter 文本框文本

I'm a bit new on this.我对此有点陌生。 Does anyone have any idea?有人有什么主意吗?

I've tried multiple things, but none have worked我尝试了很多东西,但都没有用

Replace this line替换这一行

root.textbox.configure(font=("Roboto", 14))

with this有了这个

root.textbox.configure(font='TkFixedFont')

This will use the system monospace font.这将使用系统等宽字体。 If you prefer to explicitly set it to Roboto , use Roboto Mono instead, like this:如果您更愿意将其显式设置为Roboto ,请改用Roboto Mono ,如下所示:

root.textbox.configure(font=("Roboto Mono", 14))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM