(<type 'exceptions.NameError'>, NameError("global name 'MenuPage' is not defined",), <traceback object at 0x028BEC38>)

The MenuPage contains buttons to All functions of the PDF shuffler software. This is one such function which retirieves Information about the PDF files.
Problem is, It executes once, goes back to MenuPage , then again if i click on the same function, it again executes but afterwards gives the above exception, dunno why?

How would we know, it is your code, we know nothing. MenuPage is not defined, like it says.

please show us the code to know where is the error!

Hey, Im really sorry for my noobness, i thought i had attached the files but i didnt...

Anyways, im attaching a Zip which contains:

MenuPage.py which is the Homepage containing all functions to open respective modules
InfoUI.py which is one of the modules.

Like i said before, on clicking respective module button, i want the corresponding module to Open ie its frame to show.

In the MenuPage i have created functions to open each module, they work, but only once. Ie. from MenuPage , on clicking on Info it opens Info, Info will work, then go back to MenuPage, but next time when i click on InfoUI it gives me " NAME Exception Error"... How do i tackle that? Sorry but im new to wx ..

Menu Page:

import wx
from InfoUI import *
from CropUI import *
from MergeUI import *
from RotateUI import *
from SplitUI import *
from RearrUI import *
from ConvertorUI import *
from WaterUI import *

import sys

APP_EXIT = 1

APP_NEW = 2
APP_ABOUT = 3

class MenuPage(wx.Frame):

def __init__(self, parent, title):
    super(MenuPage, self).__init__(parent, title=title, 
        size=(675,520), style=wx.MAXIMIZE_BOX 
| wx.SYSTEM_MENU | wx.CAPTION |  wx.CLOSE_BOX | wx.MINIMIZE_BOX)

    self.Centre()
    self.InitUI()       
    self.Show()




def InitUI(self):



    menubar=wx.MenuBar()

    fileMenu=wx.Menu()
    new=wx.MenuItem(fileMenu, APP_NEW, '&New\tCtrl+N')
    new.SetBitmap(wx.Bitmap('newwin.png'))
    fileMenu.AppendItem(new)
    fileMenu.AppendSeparator()
    qmi=wx.MenuItem(fileMenu, APP_EXIT, '&Quit\tCtrl+Q')
    qmi.SetBitmap(wx.Bitmap('quit.png'))
    fileMenu.AppendItem(qmi)
    menubar.Append(fileMenu,'&File')

    helpMenu=wx.Menu()
    vhelp=wx.MenuItem(helpMenu, wx.ID_HELP, '&Help\tF1')
    vhelp.SetBitmap(wx.Bitmap('newwin.png'))
    helpMenu.AppendItem(vhelp)
    helpMenu.AppendSeparator()
    about=wx.MenuItem(helpMenu, APP_ABOUT, '&About\t')
    about.SetBitmap(wx.Bitmap('quit.png'))
    helpMenu.AppendItem(about)
    menubar.Append(helpMenu,'&Help')













    self.SetMenuBar(menubar)

    self.Bind(wx.EVT_MENU, self.OnQuit, id=APP_EXIT)
    self.Bind(wx.EVT_MENU, self.OnNew, id=APP_NEW)
    self.Bind(wx.EVT_MENU, self.onAbout, id=APP_ABOUT)




    pnl=wx.Panel(self)

    font=wx.Font(22,wx.DEFAULT, wx.NORMAL, wx.BOLD)
    font1=wx.Font(16,wx.DEFAULT, wx.NORMAL, wx.NORMAL)        
    heading=wx.StaticText(pnl, label=' PDF Shuffler ', pos=(270,40))
    heading.SetFont(font)

    wx.StaticBox(pnl, -1, 'Functions', (50, 80), size=(575, 350))



    sl=wx.StaticLine(pnl, pos=(35,55), size=(610,1))

    crop=wx.StaticText(pnl, label='Crop', pos=(170, 120))
    crop.SetFont(font1)

    rotate=wx.StaticText(pnl, label='Rotate', pos=(170, 200))
    rotate.SetFont(font1)

    info=wx.StaticText(pnl, label='Document Info', pos=(170, 280))
    info.SetFont(font1)

    fmt=wx.StaticText(pnl, label='Format', pos=(170, 360))
    fmt.SetFont(font1)

    merge=wx.StaticText(pnl, label='Merge', pos=(480, 120))
    merge.SetFont(font1)

    split=wx.StaticText(pnl, label='Split', pos=(480, 200))
    split.SetFont(font1)

    rearr=wx.StaticText(pnl, label='ReArrange', pos=(480, 280))
    rearr.SetFont(font1)        

    water=wx.StaticText(pnl, label='Watermark', pos=(480, 360))
    water.SetFont(font1)


    cbtn=wx.Button(pnl, label='Crop', pos=(80,120))
    robtn=wx.Button(pnl, label='Rotate', pos=(80,200))
    ibtn=wx.Button(pnl, label='Info', pos=(80,280))
    fbtn=wx.Button(pnl, label='Convert', pos=(80,360))
    mbtn=wx.Button(pnl, label='Merge', pos=(390,120))
    sbtn=wx.Button(pnl, label='Split', pos=(390,200))
    rebtn=wx.Button(pnl, label='ReArrange', pos=(390,280))
    wbtn=wx.Button(pnl, label='Watermark', pos=(390,360))

    self.sb = self.CreateStatusBar()

    pnl.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    heading.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    crop.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    rotate.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    info.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    fmt.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    merge.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    split.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    rearr.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    water.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    #sl.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)

    cbtn.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    cbtn.Bind(wx.EVT_BUTTON, self.OnCrop)
    robtn.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    robtn.Bind(wx.EVT_BUTTON, self.OnRotate)
    ibtn.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    ibtn.Bind(wx.EVT_BUTTON, self.OnInfo)
    fbtn.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    fbtn.Bind(wx.EVT_BUTTON, self.OnCon)
    mbtn.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    mbtn.Bind(wx.EVT_BUTTON, self.OnMerge)
    sbtn.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    sbtn.Bind(wx.EVT_BUTTON, self.OnSplit)
    rebtn.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    rebtn.Bind(wx.EVT_BUTTON, self.OnRearr)
    wbtn.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
    wbtn.Bind(wx.EVT_BUTTON, self.OnWater)



def OnInfo(self,event):
   try:
       self.Inf=InfoUI(None, title='Pdf Shuffler')
       self.Inf.Show()
       self.Close()
   except:
       print "Menu Page Error"
       print sys.exc_info()

def OnNew(self, e):
    self.Menu=MenuPage(None, title='Pdf Shuffler')
    self.Close()



def OnCrop(self,event):
   self.Hide()
   self.Crp=CropUI(None, title='Pdf Shuffler')
   self.Crp.Show()

def OnMerge(self,event):
   self.Hide()
   self.Mer=MergeUI(None, title='Pdf Shuffler')
   self.Mer.Show()

def OnSplit(self,event):
   self.Hide()
   self.Spl=SplitUI(None, title='Pdf Shuffler')
   self.Spl.Show()

def OnRotate(self,event):
   self.Hide()
   self.Rot=RotateUI(None, title='Pdf Shuffler')
   self.Rot.Show()

def OnRearr(self,event):
   self.Hide()
   self.Rearr=RearrUI(None, title='Pdf Shuffler')
   self.Rearr.Show()

def OnCon(self,event):
   self.Hide()
   self.Con=ConvertorUI(None, title='Pdf Shuffler')
   self.Con.Show()



def OnWater(self,event):
   self.Hide()
   self.Wat=WaterUI(None, title='Pdf Shuffler')
   self.Wat.Show()






def OnWidgetEnter(self,e):
    name = e.GetEventObject().GetLabel()
    if name=='panel':
        self.sb.SetStatusText('Welcome to Pdf Shuffler!')
    else:
        self.sb.SetStatusText(name)
    e.Skip()



def OnQuit(self, e):
    self.Close()

def onAbout(self,e):


    description='''Pdf Shuffler is an Advanced Pdf File Manipulation Software

for Windows Operating System. Features include Merging two Pdf files, Splitting a Pdf File into
two Pdf Files, adding Watermarks, Cropping certain parts of a PDF page, converting
a Pdf file into text format and many more.
'''
info = wx.AboutDialogInfo()
info.SetName('Pdf Shuffler')
info.SetVersion('1.0')
info.SetDescription(description)

    licence = """Pdf Shuffler is free software; you can redistribute 

it and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

Pdf Shuffler is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details. You should have
received a copy of the GNU General Public License along with Pdf Shuffler;
if not, write to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston, MA 02111-1307 USA"""

    info.SetCopyright('(C) 2012 Varun Joshi')
    info.SetWebSite('http://www.varunjoshi.com')
    info.SetLicence(licence)
    info.AddDeveloper('Varun Joshi')
    info.AddDocWriter('Varun Joshi')
    info.AddArtist('Varun Joshi')
    info.AddTranslator('Varun Joshi')

    wx.AboutBox(info)

if name == 'main':

app = wx.App()
MenuPage(None, title='Pdf Shuffler')

app.MainLoop()

InfoUI:

import wx
from pyPdf import PdfFileReader,PdfFileWriter

from MenuPage import *

import sys

APP_EXIT = 1
APP_NEW = 2
APP_ABOUT = 3


class InfoUI(wx.Frame):

    def __init__(self, parent, title):
        super(InfoUI, self).__init__(parent, title=title, 
            size=(675,520), style=wx.MAXIMIZE_BOX 
    | wx.SYSTEM_MENU | wx.CAPTION |  wx.CLOSE_BOX | wx.MINIMIZE_BOX)

        self.Centre()
        self.InitUI()       
        #self.Show()


    def InitUI(self):


        menubar=wx.MenuBar()

        fileMenu=wx.Menu()
        new=wx.MenuItem(fileMenu, APP_NEW, '&New\tCtrl+N')
        new.SetBitmap(wx.Bitmap('newwin.png'))
        fileMenu.AppendItem(new)
        fileMenu.AppendSeparator()
        qmi=wx.MenuItem(fileMenu, APP_EXIT, '&Quit\tCtrl+Q')
        qmi.SetBitmap(wx.Bitmap('quit.png'))
        fileMenu.AppendItem(qmi)
        menubar.Append(fileMenu,'&File')

        helpMenu=wx.Menu()
        vhelp=wx.MenuItem(helpMenu, wx.ID_HELP, '&Help\tF1')
        vhelp.SetBitmap(wx.Bitmap('newwin.png'))
        helpMenu.AppendItem(vhelp)
        helpMenu.AppendSeparator()
        about=wx.MenuItem(helpMenu, APP_ABOUT, '&About\t')
        about.SetBitmap(wx.Bitmap('quit.png'))
        helpMenu.AppendItem(about)
        menubar.Append(helpMenu,'&Help')





        self.SetMenuBar(menubar)

        self.Bind(wx.EVT_MENU, self.OnQuit, id=APP_EXIT)
        self.Bind(wx.EVT_MENU, self.OnNew, id=APP_NEW)
        self.Bind(wx.EVT_MENU, self.onAbout, id=APP_ABOUT)








        pnl=wx.Panel(self)

        font=wx.Font(22,wx.DEFAULT, wx.NORMAL, wx.BOLD)
        font1=wx.Font(16,wx.DEFAULT, wx.NORMAL, wx.NORMAL)        
        heading=wx.StaticText(pnl, label=' PDF Shuffler ', pos=(270,40))
        heading.SetFont(font)

        wx.StaticBox(pnl, -1, 'Document Info', (50, 80), size=(575, 350))



        sl=wx.StaticLine(pnl, pos=(35,55), size=(610,1))

        oFile1=wx.StaticText(pnl, label='Original File: ', pos=(100, 120))
        oFile1.SetFont(font1)






        l1=wx.StaticText(pnl, label='( browse )', pos=(130, 145))

        #-----textbox------
        self.t2=wx.TextCtrl(pnl,-1,pos=(230, 125),size=(300,20))



        browseBtn = wx.Button(pnl, label='Browse',pos=(540,123))

        spButton = wx.Button(pnl, label='Info',pos=(320, 370))






        #-----textbox------


        self.sb = self.CreateStatusBar()

        pnl.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
        heading.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
        oFile1.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
        l1.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
        browseBtn.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
        browseBtn.Bind(wx.EVT_BUTTON, self.onBrowse)
        spButton.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
        spButton.Bind(wx.EVT_BUTTON, self.onInfo)










    def onBrowse(self, event):

        """
        Browse for file
        """
        wildcard = "Pdf files (*.pdf)|*.pdf"
        dialog = wx.FileDialog(None, "Choose a file",
                               wildcard=wildcard,
                               style=wx.OPEN)
        if dialog.ShowModal() == wx.ID_OK:
            #self.sb.SetStatusText(dialog.GetPath())
            self.t2.SetValue(dialog.GetPath())

       # self.sb.SetStatusText('Welcome to Pdf Shuffler!')
        dialog.Destroy()

    def onInfo(self, event):
        inputFile=self.t2.GetValue()

        try:
            pdf=PdfFileReader(file(inputFile,"rb"))
            try:
                info=pdf.getDocumentInfo()
                try:
                    au=info.author
                    cr=info.creator
                    pr=info.producer
                    ti=info.title
                    su=info.subject
                    pg=pdf.getNumPages()
                    wx.FutureCall(0000, self.OnAboutBox(au,cr,pr,ti,su,pg))
                    try:
                        Menu=MenuPage(None, title='Pdf Shuffler')

                    except:
                        print sys.exc_info()
                    self.Close()



                except:
                    print sys.exc_info()
                    wx.FutureCall(0000, self.PageDErrMessage)


            except:
                wx.FutureCall(0000, self.PageErrMessage)



        except:
            wx.FutureCall(0000, self.FileErrMessage)









    def OnWidgetEnter(self,e):
        name = e.GetEventObject().GetLabel()
        if name=='panel':
            self.sb.SetStatusText('Welcome to Pdf Shuffler!')
        else:
            self.sb.SetStatusText(name)
        e.Skip()

    def OnAboutBox(self,aut,cre,pro,tit,sub,pge):
        description="Author of the file is: %s\n\nCreator of the file is: %s\n\nProducer of the file is: %s\n\nTitle of the file is: %s\n\nSubject of the file is: %s\n\nNumber of Pages are: %s\n"%(aut,cre,pro,tit,sub,pge)        



        info = wx.AboutDialogInfo()
        info.SetName(' Information ')



        info.SetDescription(description)
        wx.AboutBox(info)






    def OnNew(self, e):
        self.Menu=MenuPage(None, title='Pdf Shuffler')
        self.Close()



    def OnQuit(self, e):
        self.Close()

    def ShowMessage(self):
        wx.MessageBox('Splitting Completed', 'Info', 
            wx.OK | wx.ICON_INFORMATION)

    def PageErrMessage(self):
        wx.MessageBox('No Information Found', 'Error', 
            wx.OK | wx.ICON_ERROR)

    def FileErrMessage(self):
        wx.MessageBox('File not Found', 'Error', 
            wx.OK | wx.ICON_ERROR)

    def FileDErrMessage(self):
        wx.MessageBox('Some Information Missing', 'Error', 
            wx.OK | wx.ICON_ERROR)

    def onAbout(self,e):

        description='''Pdf Shuffler is an Advanced Pdf File Manipulation Software
for Windows Operating System. Features include Merging two Pdf files, Splitting a Pdf File into
two Pdf Files, adding Watermarks, Cropping certain parts of a PDF page, converting
a Pdf file into text format and many more.
        '''
        info = wx.AboutDialogInfo()
        info.SetName('Pdf Shuffler')
        info.SetVersion('1.0')
        info.SetDescription(description)

        licence = """Pdf Shuffler is free software; you can redistribute 
it and/or modify it under the terms of the GNU General Public License as 
published by the Free Software Foundation; either version 2 of the License, 
or (at your option) any later version.

Pdf Shuffler is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
See the GNU General Public License for more details. You should have 
received a copy of the GNU General Public License along with Pdf Shuffler; 
if not, write to the Free Software Foundation, Inc., 59 Temple Place, 
Suite 330, Boston, MA  02111-1307  USA"""

        info.SetCopyright('(C) 2012 Varun Joshi')
        info.SetWebSite('http://www.varunjoshi.com')
        info.SetLicence(licence)
        info.AddDeveloper('Varun Joshi')
        info.AddDocWriter('Varun Joshi')
        info.AddArtist('Varun Joshi')
        info.AddTranslator('Varun Joshi')

        wx.AboutBox(info)







if __name__ == '__main__':

    app = wx.App()
    InfoUI(None, title='Pdf Shuffler')
    app.MainLoop()

Study style guide PEP8, at least about the using of empty lines. Your code is very hard to read, even I added the code indention to your post.

Ok Sir, ill go through it, but could you please provide me with a solution to my problem. Please!!!

Your code can not be run without MenuPage module without commenting the import statement (the pyPdf and wx I have installed) and also comment out some lines with non-existing png files.

Then after uncommenting self.Show from InfoUI's __init__ the window comes up, I can browse to a file, but there is nothing action button to do something to file. If choose New from menu, the error message window naturally comes up, because there is not class named MenuPage anywhere (and would not be with from MenuPage import * if MenuPage has not class MenuPage in it).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.