I'm making a program that shows data frame as text widget of tkinter. However, as the data increased, scroll bars were needed. I've done a lot of trials, but in the end, there is only a scroll bar in the widget of each text. Is it impossible to move more than two text widgets? Pleas help.
from tkinter import *
import pandas as pd
def focusNext(widget):
widget.tk_focusNext().focus_set()
return 'break'
def focusPrev(widget):
widget.tk_focusPrev().focus_set()
return 'break'
window2 = Tk()
columns_ = [i for i in range(0,5)]
rows = [i for i in range(0,100)]
df = pd.DataFrame(columns=columns_,index=rows,data=0)
n_rows = df.shape[0]
n_cols = df.shape[1]
column_names = df.columns
i=0
for j, col in enumerate(column_names):
text = Text(window2, width=25, height=2, bg = "#9BC2E6")
text.grid(row=i,column=j)
text.insert(INSERT, col)
text.configure(state='disabled')
cells = {}
a=0
for i in range(n_rows):
for j in range(n_cols):
locals()['text'+str(a)] = Text(window2, width=25, height=2,undo=True)
locals()['text'+str(a)].grid(row=i+1,column=j)
locals()['text'+str(a)].insert(INSERT, df.loc[i][j])
cells[(i,j)] =locals()['text'+str(a)]
if j >= 3:
locals()['text'+str(a)].tag_add(SEL, "0."+str(a), END)
locals()['text'+str(a)].mark_set(INSERT, "0."+str(a))
locals()['text'+str(a)].bind('<Tab>', lambda e, text=locals()['text'+str(a)]: focusNext(text))
locals()['text'+str(a)].bind('<Shift-Tab>', lambda e,text=locals()['text'+str(a)]: focusPrev(text))
locals()['text'+str(a)].bind('<Down>', lambda e, text=locals()['text'+str(a)]: focusNext(text))
locals()['text'+str(a)].bind('<Up>', lambda e,text=locals()['text'+str(a)]: focusPrev(text))
locals()['text'+str(a)].focus_set()
a +=1
else:
locals()['text'+str(a)].configure(state='disabled')
locals()['text'+str(0)].focus_get()
locals()['text'+str(0)].focus_set()