import wx

class McaMenu(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(640, 432))

menubar = wx.MenuBar()
file = wx.Menu() 
new = wx.MenuItem(file, 1, '&New\tCtrl+N', 'Creates a new document')
file.AppendItem(new)
file.AppendSeparator()


open = wx.MenuItem(file, 2, '&Open\tCtrl+O', 'Open New document')
file.AppendItem(open)


save = wx.MenuItem(file, 3, '&Save\tCtrl+S', 'Save')
file.AppendItem(save)


save = wx.MenuItem(file, 4, '&Save As...', 'Save As...')
file.AppendItem(save)
file.AppendSeparator()


Print = wx.MenuItem(file, 5, '&Print', 'Print')
file.AppendItem(Print)


PrintPreview = wx.MenuItem(file, 6, '&Print Preview', 'Print Preview')
file.AppendItem(PrintPreview)


PrintSetup = wx.MenuItem(file, 7, '&Print Setup', 'Print Setup')
file.AppendItem(PrintSetup)


RecentFile = wx.MenuItem(file, 8, '&Recent File', 'Recent File')
file.AppendItem(RecentFile)
file.AppendSeparator()


quit = wx.MenuItem(file, 9, '&Quit\tCtrl+Q')
file.AppendItem(quit)
self.Bind(wx.EVT_MENU, self.OnQuit, id=9)

menubar.Append(file, '&File')
self.SetMenuBar(menubar)

Edit = wx.Menu()
Edit.Append(1, 'Selection', 'Quit application')
Edit.Append(2, 'Cut', 'Quit application')
Edit.Append(3, 'Copy', 'Quit application')
Edit.Append(4, 'Paste', 'Quit application')
menubar.Append(Edit, '&Edit')
self.SetMenuBar(menubar)

View = wx.Menu()
###the python gives on this line and held my system### 
self.shtl = view.Append(1, 'Show toolbar', 'Show Toolbar', kind=wx.ITEM_CHECK)
view.Check(1, True)

self.Bind(wx.EVT_MENU, self.ToggleToolBar, id=1)

self.toolbar = self.CreateToolBar()
self.toolbar.Realize()

def ToggleToolBar(self, event):
if self.shtl.IsChecked():
self.toolbar.Show()
else:
self.toolbar.Hide()
self.Centre()
self.Show(True)

self.shst = view.Append(2, 'Status Bar', 'Status Bar', kind=wx.ITEM_CHECK)
view.Check(2, True)
self.Bind(wx.EVT_MENU, self.ToggleStatusBar, id=2)


def ToggleStatusBar(self, event):
if self.shst.IsChecked():
self.statusbar.Show()
else:
self.statusbar.Hide()
self.Centre()
self.Show(True)
View.Append(3, 'Delete Rows', 'Quit application')
menubar.Append(View, '&View')
self.SetMenuBar(menubar)

Graph = wx.Menu()
Graph.Append(1, 'Adjust Plot', 'Quit application')
Graph.Append(2, 'Scatter Plot', 'Quit application')
Graph.Append(3, 'Predict Plot', 'Quit application')
Graph.Append(4, 'Fitted vs Residual', 'Quit application')
Graph.Append(5, 'Variable vs Residual', 'Quit application')
Graph.Append(6, 'Ext Std Residual vs Fitted', 'Quit application')
menubar.Append(Graph, '&Graph')
self.SetMenuBar(menubar)

Data = wx.Menu()
Data.Append(1, 'Settings', 'Quit application')
Data.Append(2, 'Summary', 'Quit application')
Data.Append(3, 'Row Operation', 'Quit application')
Data.AppendSeparator()

Rowoperation = wx.Menu()
Rowoperation.Append(1, 'Add')
Rowoperation.Append(1, 'Delete')
Rowoperation.Append(1, 'Undelete All')

Data.AppendMenu(1, '&Rowoperation', Rowoperation)


menubar.Append(Data, '&Data')
self.SetMenuBar(menubar)

Variable = wx.Menu()
Variable.Append(1, 'Destroy', 'Quit application')
Variable.Append(2, 'Interactioin', 'Quit application')
Variable.Append(3, 'Transformation', 'Quit application')
menubar.Append(Variable, '&Variable')
self.SetMenuBar(menubar)

Correlation = wx.Menu()
Correlation.Append(1, 'Matrix', 'Quit application')
Correlation.Append(2, 'New Model', 'Quit application')
Correlation.Append(3, 'Destroy Model', 'Quit application')
Correlation.Append(4, 'Previous Model', 'Quit application')
menubar.Append(Correlation, '&Correlation')
self.SetMenuBar(menubar)

Prediction = wx.Menu()
Prediction.Append(1, 'Input Sheet', 'Quit application')
Prediction.Append(2, 'Result Sheet', 'Quit application')
Prediction.Append(3, 'Clear Input Sheet', 'Quit application')
menubar.Append(Prediction, '&Prediction')
self.SetMenuBar(menubar)

Reseduals = wx.Menu()
Reseduals.Append(1, 'All', 'Quit application')
Reseduals.Append(2, 'Delete Rows', 'Quit application')
Reseduals.Append(3, 'Included Rows', 'Quit application')
Reseduals.Append(4, '1st Outlier table', 'Quit application')
Reseduals.Append(5, '2nd Outlier table', 'Quit application')
menubar.Append(Reseduals, '&Reseduals')
self.SetMenuBar(menubar)

Help = wx.Menu()
Help.Append(1, 'Help Topics', 'Quit application')
Help.Append(2, 'About MCA', 'Quit application')
menubar.Append(Help, '&Help')
self.SetMenuBar(menubar)

self.Centre()
self.Show(True)

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

app = wx.App()
McaMenu(None, -1, 'MCA menu')
app.MainLoop()

kindly check this code and explain the possible error that i am making.
Regards
Punter

First of all: indentation would help.

What is your exact error message?

I'm getting the following error:

/usr/lib64/python2.6/site-packages/wx-2.8-gtk2-unicode/wx/_core.py:14450: UserWarning: wxPython/wxWidgets release number mismatch
  warnings.warn("wxPython/wxWidgets release number mismatch")

Are you getting the same error when you try 'import wx' in the Python interpreter?

Then you might have a look at:
https://bugzilla.redhat.com/show_bug.cgi?id=502608

I assume that you indented correctly when you tried the code on your own?

View = wx.Menu()
###the python gives on this line and held my system### 
self.shtl = view.Append(1, 'Show toolbar', 'Show Toolbar', kind=wx.ITEM_CHECK)
view.Check(1, True)

'The Python' gives on this line due to the fact that you have 'View' View = wx.Menu and then just below it you want to append to 'view'. You need to make them the same. Capitalization matters in Python variables, as it does in most programming language.

Another problem, you assign to 'save' twice'

save = wx.MenuItem(file, 3, '&Save\tCtrl+S', 'Save')
        file.AppendItem(save)


        save = wx.MenuItem(file, 4, '&Save As...', 'Save As...')
        file.AppendItem(save)
        file.AppendSeparator()

I also assume that you know that your whole gui is just the menu? You don't have anything to print, save and so on. You need to call self.Show(True) in the __init__ method. You call it within an event method. It means your gui will not be shown if that even isn't triggered, which it can't be because your gui isn't showing - chicken/egg.

i have changed the capitals to same character format but even than its giving me following errors...

Traceback (most recent call last):
  File "C:/Documents and Settings/bilal.nawaz/Desktop/kika.py", line 1, in <module>
    import wx
  File "C:\Python26\lib\site-packages\wx-2.8-msw-ansi\wx\__init__.py", line 45, in <module>
    from wx._core import *
  File "C:\Python26\lib\site-packages\wx-2.8-msw-ansi\wx\_core.py", line 5, in <module>
    import new
  File "C:\Documents and Settings\bilal.nawaz\Desktop\new.py", line 3, in <module>
  File "C:\Python26\lib\site-packages\wx-2.8-msw-ansi\wx\aui.py", line 106, in <module>
    new_instancemethod = new.instancemethod
AttributeError: 'module' object has no attribute 'instancemethod'

i have changed the capitals to same character format but even than its giving me following errors...

Traceback (most recent call last):
  File "C:/Documents and Settings/bilal.nawaz/Desktop/kika.py", line 1, in <module>
    import wx
  File "C:\Python26\lib\site-packages\wx-2.8-msw-ansi\wx\__init__.py", line 45, in <module>
    from wx._core import *
  File "C:\Python26\lib\site-packages\wx-2.8-msw-ansi\wx\_core.py", line 5, in <module>
    import new
  File "C:\Documents and Settings\bilal.nawaz\Desktop\new.py", line 3, in <module>
  File "C:\Python26\lib\site-packages\wx-2.8-msw-ansi\wx\aui.py", line 106, in <module>
    new_instancemethod = new.instancemethod
AttributeError: 'module' object has no attribute 'instancemethod'

Did you make the other changes that I mentioned? You had:

#
self.Centre()
#
self.Show(True)

within a method, which wouldn't work That is the stuff that makes the gui display itself.

You do have wxPython? Just checking.

Why don't you go through and clean it up and then post your code with the correct indentation. Looking at the way you set it up, I wonder if you have learned the basics of dealing with classes/objects in Python? Maybe you need to have a look at a good tutorial covering those subjects. My personal favorite was 'dive into Python' which covers it really nicely.

You know, working with a gui is a lot of complicated bits. If you do not have the background of knowing Python very well to begin with, you will struggle with the gui stuff...you know, you need to think frame on panel on sizer...with this event, that event. It doesn't take very long at all to get very complicated and if you are struggling with Python itself, this isn't going to be much fun. I say all this from personal experience.

import wx

class McaMenu(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(640, 432))

        menubar = wx.MenuBar()
        file = wx.Menu()     
        new = wx.MenuItem(file, 1, '&New\tCtrl+N', 'Creates a new document')
        file.AppendItem(new)
        file.AppendSeparator()

          
        open = wx.MenuItem(file, 2, '&Open\tCtrl+O', 'Open New document')
        file.AppendItem(open)
        
        
        save = wx.MenuItem(file, 3, '&Save\tCtrl+S', 'Save')
        file.AppendItem(save)
        
        
        save = wx.MenuItem(file, 4, '&Save As...', 'Save As...')
        file.AppendItem(save)
        file.AppendSeparator()

        
        Print = wx.MenuItem(file, 5, '&Print', 'Print')
        file.AppendItem(Print)
        
        
        PrintPreview = wx.MenuItem(file, 6, '&Print Preview', 'Print Preview')
        file.AppendItem(PrintPreview)
        
        
        PrintSetup = wx.MenuItem(file, 7, '&Print Setup', 'Print Setup')
        file.AppendItem(PrintSetup)
        
        
        RecentFile = wx.MenuItem(file, 8, '&Recent File', 'Recent File')
        file.AppendItem(RecentFile)
        file.AppendSeparator()

    
        quit = wx.MenuItem(file, 9, '&Quit\tCtrl+Q')
        file.AppendItem(quit)
        self.Bind(wx.EVT_MENU, self.OnQuit, id=9)
        
        menubar.Append(file, '&File')
        self.SetMenuBar(menubar)

        Edit = wx.Menu()
        Edit.Append(1, 'Selection', 'Quit application')
        Edit.Append(2, 'Cut', 'Quit application')
        Edit.Append(3, 'Copy', 'Quit application')
        Edit.Append(4, 'Paste', 'Quit application')
        menubar.Append(Edit, '&Edit')
        self.SetMenuBar(menubar)

        view = wx.Menu()
        view.Append(1, 'Status Bar', 'Quit application')
        view.Append(2, 'Toll Bar', 'Quit application')
        view.Append(3, 'Delete Rows', 'Quit application')
        menubar.Append(view, '&view')
        self.SetMenuBar(menubar)

        Graph = wx.Menu()
        Graph.Append(1, 'Adjust Plot', 'Quit application')
        Graph.Append(2, 'Scatter Plot', 'Quit application')
        Graph.Append(3, 'Predict Plot', 'Quit application')
        Graph.Append(4, 'Fitted vs Residual', 'Quit application')
        Graph.Append(5, 'Variable vs Residual', 'Quit application')
        Graph.Append(6, 'Ext Std Residual vs Fitted', 'Quit application')
        menubar.Append(Graph, '&Graph')
        self.SetMenuBar(menubar)

        Data = wx.Menu()
        Data.Append(1, 'Settings', 'Quit application')
        Data.Append(2, 'Summary', 'Quit application')
        Data.Append(3, 'Row Operation', 'Quit application')
        Data.AppendSeparator()

        Rowoperation = wx.Menu()
        Rowoperation.Append(1, 'Add')
        Rowoperation.Append(1, 'Delete')
        Rowoperation.Append(1, 'Undelete All')

        Data.AppendMenu(1, '&Rowoperation', Rowoperation)

        
        menubar.Append(Data, '&Data')
        self.SetMenuBar(menubar)

        Variable = wx.Menu()
        Variable.Append(1, 'Destroy', 'Quit application')
        Variable.Append(2, 'Interactioin', 'Quit application')
        Variable.Append(3, 'Transformation', 'Quit application')
        menubar.Append(Variable, '&Variable')
        self.SetMenuBar(menubar)

        Correlation = wx.Menu()
        Correlation.Append(1, 'Matrix', 'Quit application')
        Correlation.Append(2, 'New Model', 'Quit application')
        Correlation.Append(3, 'Destroy Model', 'Quit application')
        Correlation.Append(4, 'Previous Model', 'Quit application')
        menubar.Append(Correlation, '&Correlation')
        self.SetMenuBar(menubar)

        Prediction = wx.Menu()
        Prediction.Append(1, 'Input Sheet', 'Quit application')
        Prediction.Append(2, 'Result Sheet', 'Quit application')
        Prediction.Append(3, 'Clear Input Sheet', 'Quit application')
        menubar.Append(Prediction, '&Prediction')
        self.SetMenuBar(menubar)

        Reseduals = wx.Menu()
        Reseduals.Append(1, 'All', 'Quit application')
        Reseduals.Append(2, 'Delete Rows', 'Quit application')
        Reseduals.Append(3, 'Included Rows', 'Quit application')
        Reseduals.Append(4, '1st Outlier table', 'Quit application')
        Reseduals.Append(5, '2nd Outlier table', 'Quit application')
        menubar.Append(Reseduals, '&Reseduals')
        self.SetMenuBar(menubar)

        Help = wx.Menu()
        Help.Append(1, 'Help Topics', 'Quit application')
        Help.Append(2, 'About MCA', 'Quit application')
        menubar.Append(Help, '&Help')
        self.SetMenuBar(menubar)

        self.Centre()
        self.Show(True)
        
    def OnQuit(self, event):
        self.Close()

app = wx.App()
McaMenu(None, -1, 'MCA menu')
app.MainLoop()

this is the original code that i have written myself and now i need to add events to each tab and sum menus in that.but i dont know exactly how to do that.as i am new to python.i would appreciate if you help me out or guide me to get a good example for that.so i can get an idea about this.i have wxpython 2.8 ansi and python 2.6 installed plus im using drpython editor for modifying and writing the code.so far now i have learnt everything on myself.i don't have senior or any other person to guide me about that.your help and guidance will be beneficial for me as ia m working as an internee in a company and they don't have a senior person who can guide me.that really frustrating for me but ia m not giving up and trying to get over it by any means.

Okay, like that it works. Now, I really believe that you are going to struggle to build all the functionality with bound events for this in a forum. You are talking about hundreds of lines of code for this file you have produced.

Why not scale it down. Deal with one concept at a time. One of the main ways that you are going to deal with these events is with wxdialogs, where, on pressing something, a dialog will pop up with some options to do stuff. It is best to put these in their own module and just import them into the methods. Otherwise your code will become unmanageable.

i don't have senior or any other person to guide me about that

And as for learning yourself, well, that is the long tradition of hacking. I work in Namibia as a tour guide part of the time and thought myself html/web scripting in order to spend more time at home with my kids. If I am on tour, I carry notes on regular expression or oop or whatever I am working on, with me and learn while I am far from a computer. If I have a 15 hour day...I still take time to flip through some tutorials at night before I sleep. -- If you are learning by yourself it is more important than anything to learn one concept at a time. Be patient. I really believe that it is pointless to learn all the gui functionality when you don't have a good working knowledge of classes and inheritance, which is very much the way gui programming is taught.

I would strongly suggest, if you really must carry on with the wxpython stuff, that you cut out all that stuff in the menus, and just leave one or two. Decide what you want it to do and work on that one. Once it works, add another item and go on from there. You are going to find that you need to learn some database stuff and a fair bit of general Python stuff to manage this stuff. You will probably find that a normal handler is going to run into at least 50 lines of code, especially if you are doing dialogs in separate files.

As you build these bits, comment like mad in your own code. That way, as your program grows, you know what you did and what you plan do to.

commented: Very nice advise! +10
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.