0

My goal is to have the application structure with classes and the MVC approach following the recommendations of Bryan Oakley Ref. Stackoverflow Questions How to get variable data from a class, Calling functions from a Tkinter Frame to another, etc. and the present minimum workable example is heavily relying on Bryan's code.

I am not understanding why the frame self.frame_base = ttk.Frame(self) does not expand with the container frame container = ttk.Frame(self).

I want the Labelframe "Select Data" to fill its base window and resize with it.

I tried several ideas with no success i.e. with self.frame_base = ttk.Frame(parent) the frame and its content disappears. There is something in the parent references that I am not getting right and would appreciate any support. Regards Alioth

import tkinter as tk
import tkinter.ttk as ttk


class progTest(ttk.Frame):
    def __init__(self, parent):
        ttk.Frame.__init__(self, parent)
        self.parent = parent

        container = ttk.Frame(self)
        container.pack(side="top", fill="both", expand = True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}
        self.frames["testGui"] = testGui(parent=container)
        self.frames["testGui"].grid(row=0, column=0, sticky = 'nwes')

        frame = self.frames["testGui"]
        frame.tkraise()


class testGui(ttk.Frame):
    def __init__(self, parent):
        ttk.Frame.__init__(self, parent)
        self.parent = parent

# Calling up of the main Gui window
        self.createMainWindow(parent)


    def createMainWindow(self, parent):
        self.frame_base = ttk.Frame(self)
#        self.frame_base = ttk.Frame(parent)
        self.frame_base.grid(column = 0, row = 0, sticky = 'nwes')
        self.frame_base.columnconfigure(0, weight = 1)
        self.frame_base.rowconfigure(0, weight = 1)

        self.labelframe_flt = ttk.LabelFrame(self.frame_base, text = "Select Data", padding = 2)
        self.labelframe_flt.grid(column = 0, row = 0, sticky = "nwes", padx = 2, pady = 2)

        ttk.Label(self.labelframe_flt, text="Parameter", width = 14).grid(column = 0, row = 0, sticky = "w")
        self.combo_to = ttk.Combobox(self.labelframe_flt, width = 46)
        self.combo_to.grid(column = 1, row = 0, padx = 10, pady = 2)
        self.combo_to.config(values = ["aa", "bb", "cc", "dd"])
        self.combo_to.current(0)

        self.frame_base.columnconfigure(0, weight = 1)
        self.frame_base.columnconfigure(1, weight = 1)


#------------------------------------------------------------------------------
def main():
    root = tk.Tk()
    progTest(root).pack()
    root.minsize(500, 100)
    root.mainloop()


#------------------------------------------------------------------------------
if __name__ == '__main__' :
    main()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Alioth
  • 3
  • 2
  • Try adding `self.columnconfigure(0, weight=1)` and `self.rowconfigure(0, weight=1)` inside `testGui.__init__()`. Also change `progTest(root).pack()` to `progTest(root).pack(fill='both', expand=1)`. – acw1668 Oct 24 '20 at 17:55
  • You may want to take a look at this https://stackoverflow.com/questions/63536505/how-do-i-organize-my-tkinter-appllication/63536506#63536506# – Thingamabobs Oct 24 '20 at 18:16
  • @acw1668 Thank you for your suggestion and it works in both the minimum example from above and my application. I think I understand the addition of "fill = 'both', expand = 1" to progTest(root).pack() i.e. it tells the root window that subwidgets shall fill the window and expand with it.It is the first time I see "self.columnconfigure(0, weight=1) and self.rowconfigure(0, weight=1)" in an __init__(). Is this related to ttk.Frame.__init__(self, parent)? I was convinced that I was not properly referencing upper levels due to my class organisation. Thank you very much for your help. – Alioth Oct 24 '20 at 19:08
  • @Atlas435 Thank you for the link I will go through it. Regards – Alioth Oct 24 '20 at 19:20

0 Answers0