I am trying to add a new Frame every time the user clicks "new" on the menu,but I can't seem to somehow import the core program to add the Frame to the notebook. This is my debugging error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1470, in __call__
return self.func(*args)
File "C:\Users\Owner\Desktop\HTML IDE\UI_functions.py", line 8, in UI_add_frame
UI_notebook.add(UI_f2,text = "test")
NameError: global name 'UI_notebook' is not defined?
Here is my code:
import Tkinter
from Tkinter import *
import ttk
import UI_functions
root = Tkinter.Tk()
root.title("HTML IDE coded in Python")
w = 515
h = 590
sw = root.winfo_screenwidth()
sh = root.winfo_screenheight()
x = (sw - w)/2
y = (sh - h)/2
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
#Menu contents
UI_menu = Menu(root)
filemenu = Menu(UI_menu, tearoff=0)
filemenu.add_command(label="New",command = UI_functions.UI_add_frame)
filemenu.add_command(label="Open")
filemenu.add_command(label="Save")
filemenu.add_command(label="Save as...")
filemenu.add_command(label="Close")
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
UI_menu.add_cascade(label="File", menu=filemenu)
editmenu = Menu(UI_menu, tearoff=0)
editmenu.add_command(label="Undo")
editmenu.add_separator()
editmenu.add_command(label="Cut")
editmenu.add_command(label="Copy")
editmenu.add_command(label="Paste")
editmenu.add_command(label="Delete")
editmenu.add_command(label="Select All")
UI_menu.add_cascade(label="Edit", menu=editmenu)
helpmenu = Menu(UI_menu, tearoff=0)
helpmenu.add_command(label="Help Index")
helpmenu.add_command(label="About...")
UI_menu.add_cascade(label="Help", menu=helpmenu)
#Notebook contents
global UI_notebook
UI_notebook = ttk.Notebook(root)
UI_notebook.pack(fill="both", expand="yes")
#Nake frames for the notebook
UI_f1 = ttk.Frame()
#Add the frames to notebook
UI_notebook.add(UI_f1,text = "new")
root.config(menu=UI_menu)
root.mainloop()
That's the core of the program and this is the "UI_functions" module:
#Functions for the core program
import ttk
import Tkinter
#Add new notebook tab when user clicks "new"
def UI_add_frame():
UI_f2 = ttk.Frame()
UI_notebook.add(UI_f2,text = "test")