2

I have 2 frames inside root which called "header_frame" and "activity_frame" both are in the same column which is "column=0". I want both frames to be resizeable matching its root parent filling all empty space like this :

expected layout

I have tried all grid config possibilities including setting 'rowconfigure' on 'root', set activity_frame to stick on "North" which is header_frame, last but not least I've also tried to stick header_frame to south which is the result I do not want because those frame share same size (I hope header_frame has 'maxsize' attribute but sadly it didn't have). so this is the code that I've tried :

self.root = root
self.column = ""
self.search = ""
self.root.minsize(500,480)
self.comboboxValue = None
self.root.title("CUCI (CSV Unique Column Identifier)")
self.root.configure(background="powder blue")
self.root.grid_columnconfigure(0,weight=1)
self.root.grid_rowconfigure(0,weight=1)
self.root.grid_rowconfigure(1,weight=1)

#header frame
self.header_frame = tk.Frame(self.root)
self.header_frame.grid(row=0, column=0,sticky="NEW")
self.header_frame.grid_columnconfigure(0,weight=1)
self.header_frame.grid_rowconfigure(0,weight=1)
self.header_frame.configure(background="grey")

#activity Frame
self.activity_frame = tk.Frame(self.root)
self.activity_frame.grid(row=1, column=0,sticky="NEWS")
self.activity_frame.grid_columnconfigure(0,weight=1)
self.activity_frame.grid_rowconfigure(0,weight=1)
self.activity_frame.configure(background="grey",pady=1)

Here's the layout result from my code which I do not expect: enter image description here

The point is that I want to fill those empty spaces with activity_frame to be stick-ed on 'header_frame'.Please I do not wish to use pack(self.activity_frame.pack(fill=tk.X)). I just want to use grid because it's easy to use

greendino
  • 416
  • 3
  • 17

1 Answers1

1

The reason for the gap is because you don't have the header frame stick to the bottom of the space it was given. If you change the sticky attribute for the header to be "nsew" you'll see that the header fills the extra space.

self.header_frame.grid(row=0, column=0,sticky="nesw")

I'm guessing you don't want the header frame to be so tall. If that is the case, give row 0 a weight of 0 instead of 1. That way all extra unallocated space will be given to row 1.

self.root.grid_rowconfigure(0,weight=0)

After doing so, and after adding a couple of other widgets to simulate your screen, this is what it looks like:

Screenshot

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • i've already mentioned that in the question above. and that space is replaced by header_frame background which is grey. now the empty space is grey coloured if I do what you told me – greendino May 01 '20 at 16:04
  • 1
    @AbdullahSaid: I don't understand your comment. With these changes you get a small header, and all of the remaining space is the activity frame. Isn't that what you want? I don't know what you mean when you say "header_activity background" - what is "header_activity"? – Bryan Oakley May 01 '20 at 16:04
  • exactly. that's the point. I just want to expand the scrolled text bar if I do vertical window resizing – greendino May 01 '20 at 16:05
  • 1
    @AbdullahSaid: then this code does exactly what you want - small header and the rest of the area filled with the activity frame. – Bryan Oakley May 01 '20 at 16:06
  • oops typo. what i mean is header_frame (containing all the button except scrolled text). now how do i replace those blue gap with scrolled text bar on activity_frame – greendino May 01 '20 at 16:09
  • Your example code doesn't have a scrolled text widget or any of the other widgets. With my changes, however, the grey activity frame will fill the majority of the window, with only a small part above for the header frame. – Bryan Oakley May 01 '20 at 16:10
  • because, i've already written about 400 lines of code. it will be hard to read if I embed everything. the main problem is in the frame only. because the grey color represent how large the frame was. but the gap show blue color from root – greendino May 01 '20 at 16:11
  • My answer does exactly what you want with the code you posted - a minimal header frame, with the activity frame filling all of the rest of the window. There is no gap if yo do what is in my answer. – Bryan Oakley May 01 '20 at 16:15
  • I just did try that. and the same result with rowconfigure weight set to zero also the sticky attribute. here I provide you the screenshot: https://imgur.com/a/IDW3uoS – greendino May 01 '20 at 16:22
  • I can only work with the code you give us. My changes to the code you posted will do exactly what you want. – Bryan Oakley May 01 '20 at 16:24
  • oh my, i just put the zero weight on wrong frame, thank you very much! – greendino May 01 '20 at 16:38