1

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()
MDB
  • 11
  • 2
  • You should derive each page class from `tk.Frame` as shown in question [_Object Orientated Tkinter Functions - How would I put this in?_](http://stackoverflow.com/questions/41557785/object-orientated-tkinter-functions-how-would-i-put-this-in). Also see [_Switch between two frames in tkinter_](http://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter). – martineau Jan 10 '17 at 20:32
  • thanks...first time posting and a newbie! – MDB Jan 10 '17 at 22:08
  • 1
    Welcome to Stack Overflow! I would imagine that 95% of this code is not relevant to your question. Please create a [Minimal, Complete and Verifiable Example](http://stackoverflow.com/help/mcve) that demonstrates your issue. – Joe C Jan 10 '17 at 22:11
  • Hi Joe C, I'm not sure if my comment came through on the edit but I removed most of what I think are unnecessary and left the main file so that it displays the menu and outputs the various sample pages that I'd like to show one at a time by over-writing the previous screen. – MDB Jan 11 '17 at 03:18

0 Answers0