The below codes are for creating a table with Text() function of tkinter. I want to add a scrollbar to this window but I guess when I add scrollbar to the Text(), this method doesn't serve for scrolling the window, it's for scrolling inside the Text().
I didn't add a geometry to this example. The current geometry depends on the row and column amount. But suppose to be a fixed geometry size is requested and when we write the row and column amount, we should see the other rows and columns with this scrollbar.
from tkinter import *
class Application:
def __init__(self):
self.window = Tk()
self.window.title("Database")
self.window.resizable(width=False, height=False)
self.frame_1 = Frame(bg="black")
self.frame_1.grid(row=0, column=0)
self.menubar = Menu(tearoff=0)
self.table()
self.menu()
self.mainloop = self.window.mainloop()
def table(self):
row = int(input("Row:"))
column = int(input("Column:"))
for i in range(row):
for j in range(column):
text = Text(self.frame_1, width=20, height=1)
text.bind("<Button-3>", self.popup)
text.grid(row=i, column=j, padx=1, pady=1)
text.configure(state="disabled")
def menu(self):
self.menubar.add_command(label="Copy", command=lambda: self.window.focus_get().event_generate('<<Copy>>'))
def popup(self, event):
self.menubar.post(event.x_root, event.y_root)