简体   繁体   中英

How can i show in GUI a filtered DataFrame in python with Tkinter?

As the title suggest, I need to make a Button in a GUI (With Tkinter) that shows me a filtered DataFrame

Import of the DataFrame

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

Filtered DataFrame

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

I tried to create a GUI but when i run the code, the print function is run within my IDE (Jupyter) and not on the GUI: how can i solve this problem? The idea is to create either a new window or a list within the existing 600x600 window where all the filtered results are shown.

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)

Thanks

Try this out. To show something in GUI you have to use something like Label .

Make these changes on the function.

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)

Hope it cleared your doubt.

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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