Tkinter resizablecanvas class does not resize all the widgets and it is malfunctioning. The canvas keeps on growing. The Canvas keeps going in size. What I am trying to achieve is that I need all the widgets to be resized when I maximize the window. My code is as follows
from tkinter import *
from tkinter import ttk
class ResizingCanvas(Canvas):
def __init__(self,parent,**kwargs):
Canvas.__init__(self,parent,**kwargs)
self.bind("<Configure>", self.resize)
self.height = self.winfo_reqheight()
self.width = self.winfo_reqwidth()
def resize(self,event):
wscale = float(event.width)/self.width
hscale = float(event.height)/self.height
self.width = event.width
self.height = event.height
self.config(width=self.width, height=self.height)
self.scale("all",0,0,wscale,hscale)
print (self.width, self.height)
class Test(Frame):
def Widgets(self):
self.tabcontrol = ttk.Notebook(self)
self.mainframe = Frame(self)
self.tabcontrol.add(self.mainframe, text = "TAB-1")
self.tabcontrol.pack(fill= "both", expand = YES)
self.canvasframe = Frame(self.mainframe)
self.canvasframe.grid(row=0, column = 0)
self.canvas = ResizingCanvas(self.canvasframe)
self.canvas.grid(row=0, column = 0)
self.widgetframe = Frame(self.canvasframe)
self.canvas.create_window(100,100, window = self.widgetframe)
self.LABEL = Label(self.widgetframe, text = "LABEL-1")
self.LABEL.grid(row=1, column= 1)
self.BUTTON = Button(self.widgetframe, text = "BUTTON-1")
self.BUTTON.grid(row=1, column= 2)
self.widgetframe.update_idletasks()
def __init__(self,initial):
super(Test, self).__init__(initial)
self.grid()
self.Widgets()
root = Tk()
Software = Test(root)
root.mainloop()
Could someone please help me ? Thank you !