Python Forum
[Tkinter] Frame in canvas wont fill
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Frame in canvas wont fill
#1
i have a Canvas set in my root layout called "window".
Inside "window" i have a frame called "infill".
Inside "infill" i have a Canvas called "can" and a scrollBar called "Cscroll".
finally inside "can" i have a final Frame called "scrollArea".

I am tryin to resize "scrollArea" so it fills the "can" Canvas. I can confirm "can" fills "infill" perfectly fine, however "scrollArea" shrinks to fit the objects inside it.

I have tried a lot of stuff including, setting expand=1 and fill=BOTH in the pack options, setting width, using a bound <Configure> to update the width and rearanging the order of the elements to try pack the "scrollArea" last.
notes
1)self.TkUtil is just a reference to Tk()
2)self.cFrame and self.cButton are just functions that creates and packs the elements in a single line
3)holder is the "infill" Frame
4)i am trying to make this as modular as possible so im not using self.varables.
##part of TkUtils Module im trying to create
    def scrollable_area(self, holder):
		can= self.TkUtil.Canvas(holder)
		can.pack(side=self.TkUtil.LEFT)
		self.root.update_idletasks()
		self.root.update()
		scrollArea = self.TkUtil.Frame(can, bg="red")
		CScroll = self.TkUtil.Scrollbar(holder, orient=self.TkUtil.VERTICAL)
		CScroll.config(command=can.yview)
		CScroll.pack(side=self.TkUtil.RIGHT, fill=self.TkUtil.Y)
		scrollArea.pack(side=self.TkUtil.TOP, fill=self.TkUtil.X, expand=1)
		can.create_window(0, 0, window=scrollArea, anchor='nw')
		can.config(yscrollcommand=CScroll.set)
		scrollArea.bind("<Configure>", lambda e=self.TkUtil.Event(), c=can, s=scrollArea: self.update_scrollregion(e, c, s))
		can.bind("<Configure>", lambda e=self.TkUtil.Event(), c=can, s=scrollArea:self.OnCanvasConfigure(e, c, s))
		holder.bind("<Enter>", lambda e=self.TkUtil.Event():self.set_active(e, can))
		holder.bind("<Leave>", lambda e=self.TkUtil.Event():self.unset_active(e))
		return scrollArea

    def set_active(self, event, canvas):
		self.active_scroll = canvas
	def unset_active(self, event):
		self.active_scroll = None
	def _on_mousescroll(self, event):
		if self.active_scroll != None:
			self.active_scroll.yview_scroll(-1*(event.delta/120), "units")
	def update_scrollregion(self, event, can, scroll):
		can.configure(scrollregion=can.bbox("all"))
	def OnCanvasConfigure(self, event, can, scroll):
		canvas_width = event.width
		can.itemconfig(scroll, width = canvas_width)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  align frame inside canvas ro_btz 1 1,805 Sep-11-2020, 04:38 PM
Last Post: Larz60+
  [Tkinter] Scrollbar, Frame and size of Frame Maksim 2 8,945 Sep-30-2019, 07:30 AM
Last Post: Maksim
  [Tkinter] Resizing image inside Canvas (with Canvas' resize) Gupi 2 25,028 Jun-04-2019, 05:05 AM
Last Post: Gupi
  [Tkinter] create and insert a new frame on top of another frame atlass218 4 11,001 Apr-18-2019, 05:36 PM
Last Post: atlass218
  [Tkinter] Frame size only works if frame is empty(Solved) Tuck12173 7 6,370 Jan-29-2018, 10:44 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020