tkinter - need menu to re-write pages not buttons - screens add to, but do not replace

44 views Asked by At

I'm trying to built an app that can refresh windows from the main menu. I would rather not have separate menu buttons in the application. I've seen buttons controlling the screens but I can't seem to get my current screen to write over the existing screen.

import tkinter as tk
from tkinter import ttk
from tkinter import Menu

# set root window #
---------------
root = tk.Tk()

def _quit(): # 7
    root.quit()
    root.destroy()
    exit()

Page variable to pass for page selection
========================================

second main menu item, first submenu
------------------------------------
def newclient():#(pg_select='pg_a'):
    pg_select=('pg_a')
    pg_a(pg_select)


second main menu item, second submenu
------------------------------------
def loandetails():
    pg_select=('pg_b')
    pg_b(pg_select)


second main menu item, third submenu
------------------------------------
def intgen():
    pg_select=('pg_c')
    pg_c(pg_select)


# TOP MENU #

menu in main window
-------------------

container = tk.Frame(root)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(1, weight=1)
container.grid_columnconfigure(1, weight=1)
ttk.Label(container, text="container widget", relief='raised').grid(column=0, row=0, padx=2, pady=2, sticky='W')

menuBar = Menu(container) # 1
root.config(menu=menuBar)

#main menu first item - File (save and exit)
fileMenu = Menu(menuBar, tearoff=0) # 2
fileMenu.add_command(label="Save")
fileMenu.add_separator()
fileMenu.add_command(label="Exit", command=_quit)
menuBar.add_cascade(label="File", menu=fileMenu)

main menu second item (loan module) and first 3 sub items
---------------------------------------------------------

loanMenu = Menu(menuBar, tearoff=0) # 2
loanMenu.add_command(label="New Client", command=newclient)#calls the variable assignment
loanMenu.add_command(label="Loan Details", command=loandetails)
loanMenu.add_command(label="Interest Generator", command=intgen)
menuBar.add_cascade(label="Loan Module", menu=loanMenu)

loanMenu.add_separator()
loanMenu.add_command(label="Exit", command=_quit)

main menu (About) and 1st sub item
----------------------------------


## PAGES TO BE DISPLAYED  ##

class pg_a():
    def __init__(self, pg_select):
        label = ttk.LabelFrame(root, text="Page A!")
        label.pack(side='top')
        ttk.Label(label, text="Info for Page A", width=20, relief='raised').grid(column=0, row=0, padx=2, pady=2, sticky='W')
        pg_select=""


class pg_b():
    def __init__(self, pg_select):
        label = ttk.LabelFrame(root, text="Page B!")
        label.pack(side='top')
        ttk.Label(label, text="Info for Page B", width=20, relief='raised').grid(column=0, row=0, padx=2, pady=2, sticky='W')
        pg_select=""


class pg_c():
    def __init__(self, pg_select):
        label = ttk.LabelFrame(root, text="Page C!")
        label.pack(side='top')
        ttk.LabelFrame(label, text="Info for Page C", width=20, relief='raised').grid(column=0, row=0, padx=2, pady=2, sticky='W')
        pg_select=""


root.mainloop()
0

There are 0 answers