0

I am developing a simulation software for Mössbauer spectroscopy (Chemistry) but while designing the UI, I am facing problem while resizing the children widget with parent widget. The parent frame fills the extra space when window is maximized but the children widget doesn't changes its size.

from Tkinter import *
import ttk
import tkFileDialog as FileDialog
from PIL import Image, ImageTk
import tkFont
import matplotlib
from numpy import sin, pi

root = Tk()
# Main Container
content = ttk.Frame(root)
bold = tkFont.Font(family='Helvetica', weight='bold')
LeftFrame = ttk.Frame(content, borderwidth=5, relief="groove", width=200)
RightFrame = ttk.Frame(content, borderwidth=5, relief="groove", width=750)
text = Text(LeftFrame, height=40, width=30, padx=5, pady=5)

..... Some Codes .....

# Geometry
LeftFrame.grid(column=0, row=1, rowspan=2, sticky=(N, S, E, W))
RightFrame.grid(column=1, row=1, columnspan=3, rowspan=2, sticky=(N, S, E, W))
namelbl.grid(column=0, row=1, sticky=(N, S, E, W), padx=5)
text.grid(column=0, row=2, sticky=(N, S, E, W))

root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
content.columnconfigure(0, weight=1)
content.columnconfigure(1, weight=3)
content.columnconfigure(2, weight=3)
content.columnconfigure(3, weight=3)
content.rowconfigure(1, weight=1)

root.state("zoomed")

root.mainloop()

So, my question is How do I change the size of text widget (children) with LeftFrame (parent) in the same rate. In my case only LeftFrame is expanding while text is constant.

Software Screenshot

Riq
  • 182
  • 1
  • 2
  • 17

1 Answers1

2

You aren't giving the sticky option to the widgets inside the frame, which prevents the widgets from filling the area they have been given. Also, you aren't giving the inner frame rows and columns weights.

Any time you use grid, you should be specifying weights for the rows and columns of the parent widgets. If you have frames inside of frames, each frame is independent and needs its rows and columns configured appropriately.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • I think I am giving `sticky` option to the widget inside the frame `text.grid(column=0, row=2, sticky=(N, S, E, W))`. And I have given weight to column `content.columnconfigure(0, weight=1)`. Can you please elaborate as there are very few tutorials on Tkinter – Riq Jul 10 '14 at 18:19
  • `LeftFrame.columnconfigure(0, weight=1)` worked for me. Thanks a lot!!! I suggest you to publish a website for Tkinter tutorial as there are few resources available on internet compared to other languages. – Riq Jul 10 '14 at 18:26
  • If you don't mind, Can you please have a look at one of my question as we are unable to solve what is the problem with the code. Thanks in advance. http://stackoverflow.com/q/24748589/1581133 – Riq Jul 15 '14 at 02:13