【问题标题】:Tkinter label not show all supposed outputTkinter 标签未显示所有假定的输出
【发布时间】:2020-11-30 02:46:13
【问题描述】:

所以我编写了“a 列中第 n 个最大值的行号”,然后在 Tkinter 中实现,但是标签中显示的输出与控制台中的打印输出不同。假设控制台中的打印输出显示 3 列的值,因此 3 行,但 tkinter 仅显示 1 列的 1 行。

def row4Nthlargest(self):
    a = pd.read_csv('https://raw.githubusercontent.com/sahdan96/film_data/main/film.csv')
    b = int(self.Entry.get())
    cateogry_columns = a.select_dtypes(include=['object']).columns.tolist()
    integer_columns = a.select_dtypes(include=['int64', 'float64']).columns.tolist()
    for column in a:
        if (column in cateogry_columns):
            pass
        else:
            ans= a.nlargest(b, [column]).iloc[-1]
            self.Output_gui.configure(text = ans)

下面是我的标签代码:

self.Output_gui = tk.Label(top)
self.Output_gui.place(relx=0.027, rely=0.188, height=619, width=750)
self.Output_gui.configure(background="#ffffff")
self.Output_gui.configure(disabledforeground="#a3a3a3")
self.Output_gui.configure(foreground="#000000")
self.Output_gui.configure(justify = 'left', anchor ='nw')
self.Output_gui.configure(font=font11)
self.Output_gui.configure(wraplength="700")

tkinter label output, pycharm console output

【问题讨论】:

    标签: python pandas tkinter


    【解决方案1】:

    这段代码

    self.Output_gui.configure(text = ans)
    

    将覆盖任何以前的数据。与始终附加的终端不同。如果要在 GUI 中附加,则需要将其更改为

    self.Output_gui.configure(text = f"{self.Output_gui['text']}\n{ans}")
    

    【讨论】:

    • 我试过了,但它还是一样,让我的输出混乱..结果保持堆栈
    猜你喜欢
    • 1970-01-01
    • 2014-07-31
    • 2021-10-01
    • 2021-01-04
    • 2015-11-22
    • 2018-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多