I'm trying to make a scrollable grid table. I had a look at some answers and it seems the way is to make a Frame, then put a Canvas and a Scrollbar next to eachother and apply some commands for scrolling. I have this code here, but I can't figure out what is wrong with this.
import tkinter as tk
class Test:
def __init__(self):
self.root = tk.Tk()
table_and_scrollbar_frame = tk.Frame(self.root)
table_frame = tk.Canvas(table_and_scrollbar_frame)
table_frame.grid(row=0, column=0)
self.table_headers = ["header_1", "header_2", "header_3", "header_4"]
for test_row in range(0,100):
for header_to_create in self.table_headers:
current_entry = tk.Entry(table_frame, width=25, justify='center')
current_entry.insert(0, header_to_create + " " + str(test_row))
current_entry.configure(state='disabled', disabledforeground='blue')
current_entry.grid(row=test_row, column=self.table_headers.index(header_to_create))
table_scrollbar = tk.Scrollbar(table_and_scrollbar_frame, orient='vertical', command=table_frame.yview)
table_scrollbar.grid(row=0, column=1, sticky='ns')
table_frame.configure(yscrollcommand=table_scrollbar.set)
table_frame.config(scrollregion=table_frame.bbox("all"))
table_and_scrollbar_frame.pack()
return
if __name__ == '__main__':
program = Test()
program.root.mainloop()
I'm not sure what is wrong/missing here?
source https://stackoverflow.com/questions/75289188/trying-to-make-a-scrollable-table-with-tkinter
Comments
Post a Comment