Customtkinter 文本框忽略索引

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

我想知道是否有人可以帮忙。 我正在尝试迭代数据框以便用值填充文本框。 在 for 循环中,我修改每行的索引值。现在,我尝试将第一列输出为文本框中的一列,但值打印在一行中。我简化了代码来显示问题,数据框要大得多。代码如下:

import customtkinter as ctk
import pandas as pd

technologies = ({
    'Courses':["Spark","PySpark","Hadoop","Python","pandas","Oracle","Java"],
    'Fee' :[20000,25000,26000,22000,24000,21000,22000],
    'Duration':['30day', '40days' ,'35days', '40days', '60days', '50days', '55days']
                })

df = pd.DataFrame(technologies)

class Window(ctk.CTkToplevel):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.geometry("1000x600")

        self.textbox = ctk.CTkTextbox(master=self, width=1000, height=600, corner_radius=0)
        self.textbox.grid(row=0, column=0, sticky="nsew")


class App(ctk.CTk):
    def __init__(self):
        super().__init__()
        self.title("Creditor reports")

        self.toplevel_window = None
        self.Window = None

        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(1, weight=1)

        self.get_button = ctk.CTkButton(self, width=40, text="get", command=self.button_callback)
        self.get_button.grid(row=5, column=3, padx=10, pady=10, sticky="n", rowspan=1)
       
    def button_callback(self):
        if self.toplevel_window is None or not self.toplevel_window.winfo_exists():
            self.toplevel_window = Window(self)
        else:
            self.toplevel_window.focus()
        output_listing(self)


def output_listing(self):
    for i in range(len(df)):
        index_val = str(i) + '.0'
        print(index_val)
        self.toplevel_window.textbox.insert(index_val, df.iloc[i, 0])


if __name__ == "__main__":
    app = App()
    app.mainloop()

文本框中的输出为:

PySparkSparkHadoopPythonpandasOracleJava

打印语句输出:

0.0
1.0
2.0
3.0
4.0
5.0
6.0

任何帮助将不胜感激。我希望这只是我的一个愚蠢的疏忽。

dataframe indexing textbox customtkinter
1个回答
0
投票

试试这个:

def 输出列表(自身): 对于范围内的 i(len(df)): self.toplevel_window.textbox.insert(customtkinter.END, df.iloc[i, 0] + " ”)

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