I want my text widgets to have scrollbar capability within each text widget. I have created a canvas and within it have embedded a frame using create_window. I then put 2 Text widgets into this frame. I want each of the text widgets to have a scrollbar, however when I add the scrollbars one of them fits the entire frame whilst the second one fits half of the frame. How would I solve this problem?
import tkinter as tk
import os
import tkinter.filedialog
import tkinter.messagebox
class Main(tk.Tk):
def __init__(self, *args, **kwargs):
'''This initialisation runs the whole program'''
#textBoxList = []
tk.Tk.__init__(self, *args, **kwargs)
self.title('Untitled')
self.geometry('500x500')
self.canvas = tk.Canvas(self)
self.scroll = tk.Scrollbar(self, orient='vertical', command=self.canvas.yview)
self.canvas.configure(yscrollcommand=self.scroll.set)
self.frame = tk.Frame(self.canvas) # frame does not get pack() as it needs to be embedded into canvas throught canvas.
self.scroll.pack(side='right', fill='y')
self.canvas.pack(fill='both', expand='yes')
self.canvas.create_window((0,0), window=self.frame, anchor='nw')
self.frame.bind('<Configure>', self.canvas.configure(scrollregion=self.canvas.bbox('all')))
# 1st Text Widget
self.journal = tk.Text(self.frame)
self.vsb = tk.Scrollbar(self.frame)
self.vsb.config(command=self.journal.yview)
self.journal.config(yscrollcommand=self.vsb.set)
self.vsb.pack(side='right', fill='y')
self.journal.pack()
#2nd Text Widget
self.good = tk.Text(self.frame)
self.vsb2 = tk.Scrollbar(self.frame)
self.vsb2.config(command=self.good.yview)
self.good.config(yscrollcommand=self.vsb2.set)
self.vsb2.pack(side='right', fill='y')
self.good.pack()
root = Main()
root.mainloop()