Reputation: 75
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
Upvotes: 1
Views: 606
Reputation: 15088
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
Upvotes: 1