Skip to content Skip to sidebar Skip to footer

How Should A Scrollable Spreadsheet Be Displayed Within Tkinter?

Currently I am using a Treeview. The problem is that I am using quite a large data set. So that the GUI isn't massive, I've limited the size of the Treeview to fit the window and a

Solution 1:

I ended up using pandastable (https://github.com/dmnfarrell/pandastable). As it provided a quick and easy way of displaying data in a spreadsheet like manner. It also provides a lot of built in functionality, such as: sorting, filtering and applying functions to columns

Solution 2:

The below solution is cobbled together but should achieve the desired result:

from tkinter import *

classApp:
    def__init__(self, root):
        self.entry = []
        self.sv = []
        self.root = root
        self.canvas = Canvas(self.root, background="#ffffff", borderwidth=0)
        self.frame = Frame(self.canvas, background="#ffffff")
        self.scrolly = Scrollbar(self.root, orient="vertical", command=self.canvas.yview)
        self.scrollx = Scrollbar(self.root, orient="horizontal", command=self.canvas.xview)
        self.canvas.configure(yscrollcommand=self.scrolly.set)#, xscrollcommand=self.scrollx.set)
        self.canvas.create_window((4,4), window=self.frame, anchor="nw", tags="self.frame")
        self.scrolly.pack(side="left", fill="y")
        self.canvas.pack(side="top", fill="both", expand=True)
        self.scrollx.pack(side="bottom", fill="x")
        self.frame.bind("<Configure>", self.onFrameConfigure)
        for i inrange(15):
            self.entry.append([])
            self.sv.append([])
            for c inrange(30):
                self.sv[i].append(StringVar())
                self.sv[i][c].trace("w", lambda name, index, mode, sv=self.sv[i][c], i=i, c=c: self.callback(sv, i, c))
                self.entry[i].append(Entry(self.frame, textvariable=self.sv[i][c]).grid(row=c, column=i))
    defonFrameConfigure(self, event):
        self.canvas.configure(scrollregion=self.canvas.bbox("all"))
    defcallback(self, sv, column, row):
        print("Column: "+str(column)+", Row: "+str(row)+" = "+sv.get())

root = Tk()
App(root)
root.mainloop()

Post a Comment for "How Should A Scrollable Spreadsheet Be Displayed Within Tkinter?"