0
votes

Hi there (this is my first question)

I am building an app with Tkinter as the GUI. I want multiple frames to expand to fill out the entire root window.

With the code below, I expected the bottom (green) frame to expand all the way up to the top (cyan) frame. Instead, it stays at the bottom, and there is a "frame-less" white area between the two frames.

screenshot of an actual result when code is run

This is the code, I am executing (methods that do not mess with frame layout has been shortened out):

class CreateWindow:
def __init__(self, master, screen):
    self.master = master
    self.master.geometry('300x400')
    self.master.title("THE PROGRAM")
    self.screen = screen
    self.menu_bar = Menu(self.master)
    self.setup_menu = Menu(self.menu_bar)
    self.setup_bar()
    self.main_menu = Menu(self.menu_bar)
    self.main_bar()
    self.diary_menu = Menu(self.menu_bar)
    self.diary_bar()
    self.master.config(menu=self.menu_bar)
    # self.master.grid_columnconfigure(0, weight=1) # What is difference between these two and the two below?
    # self.master.grid_rowconfigure(0, weight=1)
    self.master.columnconfigure(0, weight=1)  
    self.master.rowconfigure(0, weight=1)
    self.top_menu(self.master)  # TODO: Make this menu actively do stuff
    if self.screen == "setup":
        setup = SetupScreen(self.master)
    elif self.screen == "main":
        setup = MainScreen(self.master)
    elif self.screen == "diary":
        setup = DiaryScreen(self.master)
    else:
        raise TypeError("wrong screen")

def setup_bar(self): ...

def main_bar(self): ...

def diary_bar(self): ...

def top_menu(self, window):  # Defines top frame : placeholder for future menu
    top = tk.Frame(window, bg='cyan', pady=5)
    top.grid(row=0, sticky='new')
    button = tk.Button(top, text="Setup", command=self.do_nothing)
    button.grid(row=0, column=0)
    button = tk.Button(top, text="Main", command=self.do_nothing)
    button.grid(row=0, column=1)
    button = tk.Button(top, text="Diary", command=self.do_nothing)
    button.grid(row=0, column=2)
    top.columnconfigure(0, weight=1)
    top.columnconfigure(1, weight=1)
    top.columnconfigure(2, weight=1)

def do_nothing(self): ...

def b_exit(self): ...


"""This class contains methods, that create and manage the setup screen. 
I want the green frame to expand all the way up to the cyan (top menu) """
class SetupScreen(CreateWindow):
def __init__(self, master):
    self.master = master
    self.menu = tk.Frame(self.master, bg='green')
    self.menu.grid(row=1, sticky='new')
    self.menu.columnconfigure(0, weight=1) # Again, what is difference between 'grid_'or not?
    self.menu.grid_rowconfigure(1, weight=1) #I have tried setting index to both 0 and 1, no difference
    self.create_buttons()

def create_buttons(self): ...

def personal_details(self): ...

def start_new(self):
    pass

if __name__ == "__main__":
files = FileHandler() #Class meant to be handling file operations - currently only sets a boolean to false, that makes the app start with setup screen
ap = files.active_program
print(ap)
root = tk.Tk()
if not files.active_program: #based on the boolean from FileHandler class, this starts the setup screen
    top_menu = CreateWindow(root, "setup")
else:
    top_menu = CreateWindow(root, "main")
root.mainloop()
1

1 Answers

0
votes

It looks like you're trying to create a notebook widget with several tabs.

So I would suggest you use ttk.Notebook instead of re-inventing it yourself.