0

I'm looking into making a button that displays a dataframe in a new window in my Tkinter app. Did some googling but couldn't find anything. Any ideas? Much appreciated!!


class MyApp():
    def __init__(self, master):
        self.master = master
        master.title("My App")
        self.button1 = Button(master, text="Display df", command=self.display_df_in_new_window)
        self.button1.place(x=60, y=100,height = 44, width = 127)

    def get_data(self):
      ##code to get data
        return df

    def display_df_in_new_window(self):
       ## code

root = Tk()
my_gui = MyApp(root)
root.geometry("600x450")
root.mainloop()
3
  • What do you mean by df? are you talking about pandas dataframe? Commented Apr 11, 2022 at 12:02
  • Yes. A button that displays a pandas dataframe in a new window. sorry for the confusion! Commented Apr 11, 2022 at 12:04
  • Does this answer your question? How to display a dataframe in tkinter Commented Apr 11, 2022 at 12:15

1 Answer 1

2

I modified your code a bit so that it is now opening a new window to show data frame of pandas, for test purpose i generated dummy test data, you can replace that part with your own data frame to show.

from tkinter import *
from pandastable import Table, TableModel

class MyApp():
    def __init__(self, master):
        self.master = master
        master.title("My App")
        self.button1 = Button(master, text="Display df", command=self.display_df_in_new_window)
        self.button1.place(x=60, y=100,height = 44, width = 127)

    def get_data(self):
      ##code to get data
      #generating sample data for test purpose replace with your own df
        df = TableModel.getSampleData()
        return df

    def display_df_in_new_window(self):
       frame = Toplevel(self.master) #this is the new window
       self.table = Table(frame, dataframe=self.get_data(), showtoolbar=True, showstatusbar=True)
       self.table.show()

root = Tk()
my_gui = MyApp(root)
root.geometry("600x450")
root.mainloop()

Output will be something like below

Output screenshot on Ubuntu 20.04

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.