0

I have a toplevel window in which I created a canvas and a frame within it to support scrolling functionallity.

Part of the canvas and frame code looks like this:

    ##Canvas
    self.canvas = tk.Canvas(self.toplevel, borderwidth=0)
    self.canvas.bind_all("<MouseWheel>", self.__on_mousewheel)
    self.canvas.pack(side="left", fill="both", expand=True)

    ##Frame 
    self.frame = tk.Frame(self.canvas, background="red")
    self.frame.bind("<Configure>", lambda event, canvas=self.canvas: self.__on_frame_configure())
    self.canvas.create_window((1,1), window=self.frame, anchor="n")

......

"Later" in the code I populate the frame with a dynamically generated number of checkbuttons. (depends on user input)

Problem #1

I can not retrieve the width (preferably in pixels) of the text attribute of checkbuttons. I have found a workaround for that!

Problem #2

I want to programmatically resize the width of the frame.

    self.frame.update()


    print("Im here",self.frame.winfo_width())
    self.frame.configure(width=self.frame.winfo_width() + 30)
    print("Now im here",self.frame.winfo_width())


    self.canvas.configure(width=self.frame.winfo_width())
    self.canvas.configure(height=self.frame.winfo_height())

Outcome of print statements:

Im here 904

Now im here 934

When I inspect the gui, I notice that only that canvas gets resized.

Pic of the right part of the gui which is supposed to be filled in with red background of the frame.

Pic of the right part of the gui which is supposed to be filled in with the red background of the frame

panos
  • 328
  • 1
  • 4
  • 16
  • You want to resize the frame with the canvas, correct? What else you would like to resize with the canvas ? Your question isnt clear to me, what is the goal? – Thingamabobs Dec 31 '20 at 11:04
  • I only want to resize the frame, which has a red background. Have a look of the pic and youll understand. The canvas is resized but the frame doesn't occupy the full canvas. – panos Dec 31 '20 at 11:12

0 Answers0