【问题标题】:How can i show in GUI a filtered DataFrame in python with Tkinter?我如何在 GUI 中使用 Tkinter 在 python 中显示过滤的 DataFrame?
【发布时间】:2020-09-10 07:33:45
【问题描述】:

正如标题所示,我需要在 GUI(使用 Tkinter)中制作一个按钮,显示过滤后的 DataFrame

数据帧的导入

df = pd.read_csv (r'C:\Users\shold\Downloads\df.csv')
df = df[['A', 'B', 'C', 'D', 'E', 'F', 'G']]

过滤后的数据帧

FIltered_df= df.drop_duplicates(subset=['G'])
FIltered_df= FIltered_df.iloc[:,[0,6]]

我尝试创建一个 GUI,但是当我运行代码时,打印功能在我的 IDE (Jupyter) 中运行,而不是在 GUI 上:我该如何解决这个问题?这个想法是在现有的 600x600 窗口中创建一个新窗口或一个列表,其中显示所有过滤的结果。

window = tk.Tk()
window.geometry("600x600")
window.title("GUI")
def first_print():
    text ="Filter the df"
    text_output = tk.Label(window, text=text)
    text_output.grid(row=0, column=1, padx = 50)
    print(FIltered_df)
    
first_button = tk.Button(text="Filter the df", command=first_print)
first_button.grid(row=0, column=0)

谢谢

【问题讨论】:

    标签: python pandas dataframe user-interface tkinter


    【解决方案1】:

    试试这个。要在 GUI 中显示某些内容,您必须使用 Label 之类的内容。

    对函数进行这些更改。

    def first_print():
        text ="Filter the df"
        text_output = tk.Label(window, text=text)
        text_output.grid(row=0, column=1, padx = 50)
        text = tk.Label(window,text=Filtered_df,font=('monospace',11)) #font=(family,size)
        text.grid(row=1,column=1)
    

    希望它能消除您的疑虑。

    干杯

    【讨论】:

    • 为了更好地查看,请使用等宽字体,例如 TkFixedFontConsolas
    猜你喜欢
    • 2018-06-26
    • 2019-08-12
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    • 2021-10-22
    • 1970-01-01
    • 2018-06-22
    相关资源
    最近更新 更多