12 Replies - 2911 Views - Last Post: 28 March 2011 - 07:42 AM Rate Topic: -----

#1 CodyD  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 75
  • Joined: 19-August 10

Importing external menu into tkinter python program

Posted 23 March 2011 - 01:20 PM

Hi there everyone, I'm starting a large based program, so I'm splitting it into multiple files. I need some help with this however.


I have written a menu in a file called "menu.py"
The main program is in the file called "main.py"

How do I import menu.py into main.py and have the menu show up.

Here is my current code in main.py:

from Tkinter import *
from menu import *

root = Tk()

def body(self, master):
    menu.menu()
    menu.menu.pack()

root.mainloop()



Menu.py:
from Tkinter import *    

def menu(self, master):    
    menubar = Menu(root)
    filemenu = Menu(menubar, tearoff=0)
    filemenu.add_command(label="New", command=donothing)
    filemenu.add_command(label="Open", command=donothing)
    filemenu.add_command(label="Save", command=donothing)
    filemenu.add_command(label="Save as...", command=donothing)
    filemenu.add_command(label="Close", command=donothing)

    filemenu.add_separator()

    filemenu.add_command(label="Exit", command=root.quit)
    menubar.add_cascade(label="File", menu=filemenu)
    editmenu = Menu(menubar, tearoff=0)
    editmenu.add_command(label="Undo", command=donothing)

    editmenu.add_separator()

    editmenu.add_command(label="Cut", command=donothing)
    editmenu.add_command(label="Copy", command=donothing)
    editmenu.add_command(label="Paste", command=donothing)
    editmenu.add_command(label="Delete", command=donothing)
    editmenu.add_command(label="Select All", command=donothing)

    menubar.add_cascade(label="Edit", menu=editmenu)
    helpmenu = Menu(menubar, tearoff=0)
    helpmenu.add_command(label="Help Index", command=donothing)
    helpmenu.add_command(label="About...", command=donothing)
    menubar.add_cascade(label="Help", menu=helpmenu)

    root.config(menu=menubar)
    root.mainloop()

This post has been edited by CodyD: 23 March 2011 - 01:28 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Importing external menu into tkinter python program

#2 CodyD  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 75
  • Joined: 19-August 10

Re: Importing external menu into tkinter python program

Posted 23 March 2011 - 01:54 PM

I decided to combine this part of the program. It's not too long..


Here is the new code:

from Tkinter import *

root = Tk()

class body:
    
    def donothing():
        pass

    def menu():
        root=Tk()
        
        menubar = Menu(root)
        filemenu = Menu(menubar, tearoff=0)
        filemenu.add_command(label="New", command=donothing)
        filemenu.add_command(label="Open", command=donothing)
        filemenu.add_command(label="Save", command=donothing)
        filemenu.add_command(label="Save as...", command=donothing)
        filemenu.add_command(label="Close", command=donothing)

        filemenu.add_separator()

        filemenu.add_command(label="Exit", command=root.quit)
        menubar.add_cascade(label="File", menu=filemenu)
        editmenu = Menu(menubar, tearoff=0)
        editmenu.add_command(label="Undo", command=donothing)

        editmenu.add_separator()

        editmenu.add_command(label="Cut", command=donothing)
        editmenu.add_command(label="Copy", command=donothing)
        editmenu.add_command(label="Paste", command=donothing)
        editmenu.add_command(label="Delete", command=donothing)
        editmenu.add_command(label="Select All", command=donothing)

        menubar.add_cascade(label="Edit", menu=editmenu)
        helpmenu = Menu(menubar, tearoff=0)
        helpmenu.add_command(label="Help Index", command=donothing)
        helpmenu.add_command(label="About...", command=donothing)
        menubar.add_cascade(label="Help", menu=helpmenu)
        
        def file_open(self):
            """open a file to read"""
            # optional initial directory (default is current directory)
            initial_dir = "C:\Temp"
            # the filetype mask (default is all files)
            mask = \
            [("Text and Python files","*.txt *.py *.pyw"),
            ("HTML files","*.htm"),
            ("All files","*.*")]
            fin = askopenfile(initialdir=initial_dir, filetypes=mask, mode='r')
            text = fin.read()
            if text != None:
                self.text.delete(0.0, END)
                self.text.insert(END,text)
             
        def file_save(self):
            """get a filename and save the text in the editor widget"""
            # default extension is optional, here will add .txt if missing
            fout = asksaveasfile(mode='w', defaultextension=".txt")
            text2save = str(self.text.get(0.0,END))
            fout.write(text2save)
            fout.close()

root.config(menu=body.menu.menubar)
app = body()
root.mainloop()



Here's the error:
Traceback (most recent call last):
File "/home/cody/Pivot: Revolution/main.py", line 72, in <module>
root.config(menu=body.menu.menubar)
AttributeError: 'function' object has no attribute 'menubar'
Script terminated.
Was This Post Helpful? 0
  • +
  • -

#3 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Importing external menu into tkinter python program

Posted 23 March 2011 - 01:54 PM

I made a few tiny edits to your code:
  • I had to give donothing a value so that menu would run
  • I made root a parameter
  • I got rid of the needless self,master parameters
  • I changed body to main as a matter of preference and style (you can undo that)
  • When you use from module import * you don't need to give the name of the module when calling on one of its' functions. I changed Main to only import the menu function. As a rule, I try to only import what I need. You may add more methods to Menu.py that Main shouldn't access.


from Tkinter import *    

def menu(root):
    donothing=""
    menubar = Menu(root)
    filemenu = Menu(menubar, tearoff=0)
    filemenu.add_command(label="New", command=donothing)
    filemenu.add_command(label="Open", command=donothing)
    filemenu.add_command(label="Save", command=donothing)
    filemenu.add_command(label="Save as...", command=donothing)
    filemenu.add_command(label="Close", command=donothing)

    filemenu.add_separator()

    filemenu.add_command(label="Exit", command=root.quit)
    menubar.add_cascade(label="File", menu=filemenu)
    editmenu = Menu(menubar, tearoff=0)
    editmenu.add_command(label="Undo", command=donothing)

    editmenu.add_separator()

    editmenu.add_command(label="Cut", command=donothing)
    editmenu.add_command(label="Copy", command=donothing)
    editmenu.add_command(label="Paste", command=donothing)
    editmenu.add_command(label="Delete", command=donothing)
    editmenu.add_command(label="Select All", command=donothing)

    menubar.add_cascade(label="Edit", menu=editmenu)
    helpmenu = Menu(menubar, tearoff=0)
    helpmenu.add_command(label="Help Index", command=donothing)
    helpmenu.add_command(label="About...", command=donothing)
    menubar.add_cascade(label="Help", menu=helpmenu)

    root.config(menu=menubar)
    root.mainloop()


from Tkinter import *
from menu import menu


def body():
    root = Tk()
    menu(root)



EDIT:
Looking at your second post, your problem is a result of #5 on my list. In other words menu.menu() should be menu().

This post has been edited by atraub: 23 March 2011 - 01:58 PM

Was This Post Helpful? 0
  • +
  • -

#4 CodyD  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 75
  • Joined: 19-August 10

Re: Importing external menu into tkinter python program

Posted 23 March 2011 - 06:13 PM

That worked like a charm :) Thanks atraub. New problem arises. I just designed the main interface (hopefully, not able to see it yet.)


Here is my code (main.py):
from Tkinter import *
from menu import menu
from loadsave import file_open
from loadsave import file_save
from userinterface.py import mainInterface

root = Tk()

def body():
    menu(root)
    mainInterface(root)
    
def fileopen():
    file_open(self)
    
def filesave():
    file_save()

app = body()
root.mainroot()



Here is the UI code (userinterface.py):
"""
Program: Pivot: Revolution
Author: Cody Dostal
e-Mail: CodDosta@uat.edu
License: None as of now
"""

from Tkinter import *

class mainInterace(Frame):
    do_nothing=""
    root = Tk()
    playButton = Button(text = "Play", command = do_nothing)
    playButton.grid(column = 1, row = 2)
    stopButton = Button(text = "Stop", command = do_nothing)
    stopButton.grid(column = 1, row = 3)
    loopCheck = Checkbutton()
    loopCheck.grid(column = 1, row = 4)
    loopLabel = Label(text="Loop Animation")
    loopLabel.grid(column = 1, row = 5)
    fpsRate = Scale(orient=VERTICAL)
    fpsRate.grid(column = 2, row = 1)
    
    optionList = ("Train, Boat", "plane")
    options = StringVar()
    options.set(optionList[0])
    chooseFig = OptionMenu(options, optionList)
    chooseFig.grid(column = 1, row = 6)
    addfigButton = Button(text="Add Figure", command = do_nothing)
    addfigButton.grid(column=1, row = 7)
    
    delfigButton = Button(text="Delete", command = do_nothing)
    delfigButton.grid(column = 1, row = 8)
    editfigButton = Button(text="Edit", command = do_nothing)
    delfigButton.grid(column = 2, row = 8)
    centfigButton = Button(text="Center", command = do_nothing)
    delfigButton.grid(column = 1, row = 9)
    flipfigButton = Button(text="Flip", command = do_nothing)
    delfigButton.grid(column = 2, row = 9)
    colorfigBtn = Button(text="Color", command = do_nothing)
    delfigButton.grid(column = 1, row = 10)
    figSize = SpinBox()
    delfigButton.grid(column = 2, row = 10)
    
    newFrameBtn = Button(text="New Frame", command = do_nothing)
    newFrameBtn.grid(column = 1, row = 11)
    
    mainArea = Canvas()
    mainArea.grid(column =3, row = 2)
    
    root.mainloop()



My Error:
Traceback (most recent call last):
File "/home/cody/Pivot: Revolution/userinterface.py", line 10, in <module>
class mainInterace(Frame):
File "/home/cody/Pivot: Revolution/userinterface.py", line 27, in mainInterace
chooseFig = OptionMenu(options, optionList)
TypeError: __init__() takes at least 4 arguments (3 given)
Script terminated.
Was This Post Helpful? 0
  • +
  • -

#5 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Importing external menu into tkinter python program

Posted 23 March 2011 - 06:23 PM

you're missing some code there friend... in particular, the part where you define OptionMenu.

OptionMenu has 3 parameters, you've only supplied two arguments. You'll need to show more code before I can help you further.
Was This Post Helpful? 0
  • +
  • -

#6 CodyD  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 75
  • Joined: 19-August 10

Re: Importing external menu into tkinter python program

Posted 23 March 2011 - 06:27 PM

That's all my code, apart from the saving loading code, and from the menu (which you already helped with) if I write self in front of all them (for parent = self) it says:
Traceback (most recent call last):
File "/home/cody/Pivot: Revolution/main.py", line 12, in <module>
from userinterface.py import mainInterface
File "/home/cody/Pivot: Revolution/userinterface.py", line 10, in <module>
class mainInterace(Frame):
File "/home/cody/Pivot: Revolution/userinterface.py", line 27, in mainInterace
chooseFig = OptionMenu(self, options, optionList)
NameError: name 'self' is not defined
Script terminated.
Was This Post Helpful? 0
  • +
  • -

#7 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Importing external menu into tkinter python program

Posted 23 March 2011 - 08:06 PM

D'oh! OptionMenu is built into tkinter lolz.You just need to set some options in your option menu. Here's a link with more information on the OptionMenu widget.

This post has been edited by atraub: 23 March 2011 - 08:16 PM

Was This Post Helpful? 0
  • +
  • -

#8 CodyD  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 75
  • Joined: 19-August 10

Re: Importing external menu into tkinter python program

Posted 23 March 2011 - 08:15 PM

:P Yeah, so whats causing my code to spaz out. Do you know??
Was This Post Helpful? 0
  • +
  • -

#9 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Importing external menu into tkinter python program

Posted 24 March 2011 - 06:28 AM

Good news, I can make it run. Bad news, it don't look pretty:
"""
Program: Pivot: Revolution
Author: Cody Dostal
e-Mail: CodDosta@uat.edu
License: None as of now
"""

from Tkinter import *

def mainInterace():
    do_nothing=""
    root = Tk()
    playButton = Button(text = "Play", command = do_nothing)
    playButton.grid(column = 1, row = 2)
    stopButton = Button(text = "Stop", command = do_nothing)
    stopButton.grid(column = 1, row = 3)
    loopCheck = Checkbutton()
    loopCheck.grid(column = 1, row = 4)
    loopLabel = Label(text="Loop Animation")
    loopLabel.grid(column = 1, row = 5)
    fpsRate = Scale(orient=VERTICAL)
    fpsRate.grid(column = 2, row = 1)
    
    options = StringVar(root)
    chooseFig = OptionMenu(root, options, "Train, Boat", "plane")
    chooseFig.grid(column = 1, row = 6)
    addfigButton = Button(text="Add Figure", command = do_nothing)
    addfigButton.grid(column=1, row = 7)
    
    delfigButton = Button(text="Delete", command = do_nothing)
    delfigButton.grid(column = 1, row = 8)
    editfigButton = Button(text="Edit", command = do_nothing)
    delfigButton.grid(column = 2, row = 8)
    centfigButton = Button(text="Center", command = do_nothing)
    delfigButton.grid(column = 1, row = 9)
    flipfigButton = Button(text="Flip", command = do_nothing)
    delfigButton.grid(column = 2, row = 9)
    colorfigBtn = Button(text="Color", command = do_nothing)
    delfigButton.grid(column = 1, row = 10)
    #figSize = SpinBox()
    delfigButton.grid(column = 2, row = 10)
    
    newFrameBtn = Button(text="New Frame", command = do_nothing)
    newFrameBtn.grid(column = 1, row = 11)
    
    mainArea = Canvas()
    mainArea.grid(column =3, row = 2)
    
    root.mainloop()


Was This Post Helpful? 0
  • +
  • -

#10 CodyD  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 75
  • Joined: 19-August 10

Re: Importing external menu into tkinter python program

Posted 26 March 2011 - 04:41 PM

Atarub, I switched to wxPython (seems more mature, and runs nicer)

2 problems though:

1. The menubar is sporadic. It likes to sometimes show then othertimes not... That's not exactly good for a program to be released in the future :P

2. The menubar will NOT import from the external menu file. So the code is currently in the same file.

"""
Program: Pivot: Revolution
Author: Cody Dostal
e-Mail: CodyDostal@gmail.com
License: None as of now
"""

from wx import *
from os import *

class mainInterface(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(700,650))
##        frameSelect = wx.BORDER_SUNKEN(self, pos=(10, 10) size=(660, 30))
        playButton = wx.Button(self, label = "Play", pos=(10,100))
        stopButton = wx.Button(self, label = "Stop", pos=(10,140))
##        self.loopCheck = wx.CHK_2STATE()
##        self.fpsSelect = wx.SB_VERTICAL()
        #Stick Selector
        self.addButton = wx.Button(self, label = "Add figure", pos=(10,300))
        
        self.deleteButton = wx.Button(self, label = "Delete", pos=(10,380))
        self.editButton = wx.Button(self, label = "Edit", pos=(100,380))
        self.centerButton = wx.Button(self, label = "Edit", pos=(10,440))
        self.flipButton = wx.Button(self, label = "Flip", pos=(100,440))
        self.colorButton = wx.Button(self, label = "Color", pos=(10,500))
        #Stick Size Selector
        self.nextButton = wx.Button(self, label = "Next Frame", pos=(10,560))
        # Add the Canvas)
    
        # Create the StatusBar
        self.CreateStatusBar()
        
        
        menuBar = wx.MenuBar()
        
        # Creating the menu
        filemenu = wx.Menu()
        helpmenu = wx.Menu()
        optionsmenu = wx.Menu()
        
        # Creating the file menu
        filemenu.Append(wx.ID_NEW, "&New", "Open a new window.")
        filemenu.Append(wx.ID_OPEN, "O&pen", "Open a file.")
        filemenu.Append(wx.ID_SAVE, "S&ave", "Save a file.")
        filemenu.AppendSeparator()
        filemenu.Append(wx.ID_EXIT, "E&xit", "Exit the program.")
        
        # Creating the help menu
        helpmenu.Append(wx.ID_ABOUT, "&About", "About the Program")
        helpmenu.Append(wx.ID_HELP, "&Help", "Get help with this program.")
        helpmenu.AppendSeparator()
        helpmenu.Append(wx.ID_FILE1, "Check for &Updates...", "Check for Updates to Pivot: Revolution")
        
        menuBar.Append(filemenu, "&File")
        menuBar.Append(optionsmenu, "&Options")
        menuBar.Append(helpmenu, "&Help")
        self.SetMenuBar(menuBar)
        self.Show(True)
        
app = wx.App(False)
frame = mainInterface(None, "Pivot: Revolution")
app.MainLoop()



How I import it from the external file follows:
from menu import menu


Then above the main UI, I type:
menu()
Error:
Traceback (most recent call last):
File "/home/cody/Pivot: Revolution/userinterface.py", line 37, in <module>
frame = mainInterface(None, "Pivot: Revolution")
File "/home/cody/Pivot: Revolution/userinterface.py", line 15, in __init__
menu()
File "/home/cody/Pivot: Revolution/menu.py", line 33, in menu
self.SetMenuBar(menuBar)
NameError: global name 'self' is not defined
Script terminated.

So I try:
menu(self)

Error:
Traceback (most recent call last):
File "/home/cody/Pivot: Revolution/userinterface.py", line 37, in <module>
frame = mainInterface(None, "Pivot: Revolution")
File "/home/cody/Pivot: Revolution/userinterface.py", line 15, in __init__
menu(self)
TypeError: menu() takes no arguments (1 given)
Script terminated.

So as a last resort, I try
menu(root)

Error:
Traceback (most recent call last):
File "/home/cody/Pivot: Revolution/userinterface.py", line 37, in <module>
frame = mainInterface(None, "Pivot: Revolution")
File "/home/cody/Pivot: Revolution/userinterface.py", line 15, in __init__
menu(root)
NameError: global name 'root' is not defined
Script terminated.

The code for menu.py:
"""
Program: Pivot: Revolution
Author: Cody Dostal
e-Mail: CodyDostal@gmail.com
License: None as of now
"""

from wx import * 
def menu():
    menuBar = wx.MenuBar()
    
    # Creating the menu
    filemenu = wx.Menu()
    helpmenu = wx.Menu()
    optionsmenu = wx.Menu()
    
    # Creating the file menu
    filemenu.Append(wx.ID_NEW, "&New", "Open a new window.")
    filemenu.Append(wx.ID_OPEN, "O&pen", "Open a file.")
    filemenu.Append(wx.ID_SAVE, "S&ave", "Save a file.")
    filemenu.AppendSeparator()
    filemenu.Append(wx.ID_EXIT, "E&xit", "Exit the program.")
    
    # Creating the help menu
    helpmenu.Append(wx.ID_ABOUT, "&About", "About the Program")
    helpmenu.Append(wx.ID_HELP, "&Help", "Get help with this program.")
    helpmenu.AppendSeparator()
    helpmenu.Append(wx.ID_FILE1, "Check for &Updates...", "Check for Updates to Pivot: Revolution")
    
    menuBar.Append(filemenu, "&File")
    menuBar.Append(optionsmenu, "&Options")
    menuBar.Append(helpmenu, "&Help")
    self.SetMenuBar(menuBar)
    Show(True)


Was This Post Helpful? 0
  • +
  • -

#11 CodyD  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 75
  • Joined: 19-August 10

Re: Importing external menu into tkinter python program

Posted 27 March 2011 - 10:46 AM

D'oh! I forgot Ubuntu 11.04 puts the menu on the top bar! XD Okay, so I got it working fine with the following code in userinterface.py:
##Pivot: Revolution is a stickfigure Animator designed to allow simplicity when animating.
##Copyright (C) 2011  Cody Dostal <#############>

##This program is free software: you can redistribute it and/or modify
##it under the terms of the GNU Affero General Public License as
##published by the Free Software Foundation, either version 3 of the
##License, or (at your option) any later version.
##
##This program 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 Affero General Public License for more details.
##
##You should have received a copy of the GNU Affero General Public License
##along with this program.  If not, see <http://www.gnu.org/licenses/>.

from wx import *
import os
from menu import menu
from loadsave import open_file
from loadsave import save_file

class mainInterface(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, None, -1, "Pivot: Revolution", size=(700,650))
        self.currentDirectory = os.getcwd()
       
    
        menu(self)
        
        Panel = wx.Panel(self, wx.ID_ANY)
        frameSelect = wx.Panel(self, -1, pos=(10, 10), size = (690, 80), style = wx.RAISED_BORDER)
        playButton = wx.Button(self, label = "Play", pos=(10,100))
        stopButton = wx.Button(self, label = "Stop", pos=(10,140))
        loopCheck = wx.CheckBox(self, -1, "Repeat Animation", pos=(10, 190), )
        fpsSelect = wx.SpinCtrl(self, -1, pos=(100, 100), size=(45, 30), min=10, max=35, initial=25)
        fpsLabel = wx.StaticText(self, -1, label="FPS", pos=(107, 130))
        
        stickSelect2 = wx.ComboBox(self, -1, choices="EmptyList", pos=(10, 260))
        addButton = wx.Button(self, label = "Add figure", pos=(10,300))
        
        deleteButton = wx.Button(self, label = "Delete", pos=(10,380))
        editButton = wx.Button(self, label = "Edit", pos=(100,380))
        centerButton = wx.Button(self, label = "Edit", pos=(10,440))
        flipButton = wx.Button(self, label = "Flip", pos=(100,440))
        colorButton = wx.Button(self, label = "Color", pos=(10,500))
        stickSize = wx.SpinCtrl(self, -1, min=0, max=999, initial=100, pos=(100, 500), size=(85, 30))
        nextButton = wx.Button(self, label = "Next Frame", pos=(10,560))
        # Add the Canvas
    
        # Create the StatusBar
        self.CreateStatusBar()
        
        # Set Event Numbers
        ID_NEW = 100
        ID_OPEN = 101
        ID_SAVE = 102
        ID_EXIT = 103
        ID_ABOUT = 104
        ID_HELP = 105
        ID_FILE1 = 106
        
        # Bind Objects
    
    def exitmenu(self, event):
        self.Close(True)
        self.Destroy()
    
    def newWindow(self, event):
        msgbox = wx.MessageBox("I'm sorry, but this function is not yet implemented!", caption="Error!", style=wx.OK)
        
    def openFile(self, event):
        open_file(self)
        
    def saveFile(self, event):
        save_file(self)
        
    def aboutDlg(self, event):
        description = """Pivot: Revolution is an advanced animation program that allows
        physics based animations using pre-defined stick figures that are usually developed
        by third-party developers.
"""

        licence = """Pivot: Revolution 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 3 of the License, or (at your option) any later version.

Pivot: Revolution 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 Pivot: Revolution; if not, write to 
the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA"""


        info = wx.AboutDialogInfo()

        info.SetIcon(wx.Icon('images/pivot revolution.png', wx.BITMAP_TYPE_PNG))
        info.SetName('Pivot: Revolution')
        info.SetVersion('1.0')
        info.SetDescription(description)
        info.SetCopyright('(C) 2011 Cody Dostal')
        info.SetWebSite('http://codyd8100.weebly.com')
        info.SetLicence(licence)
        info.AddDeveloper('Cody Dostal')
        info.AddDocWriter('Cody Dostal')
        info.AddArtist('Pivot Palace')
        info.AddTranslator('Cody Dostal')

        wx.AboutBox(info)

        
    def helpDlg(self, event):
        OnAboutBox()
        
    def updateDlg(self, event):
        msgbox = wx.MessageBox("I'm sorry, but this function is not yet implemented!", caption="Error!", style=wx.OK)
        
    def canvasSize(self, event):
        msgbox = wx.MessageBox("I'm sorry, but this function is not yet implemented!", caption="Error!", style=wx.OK)
        
if __name__ == "__main__":
    app = wx.App(False)
    frame = mainInterface(None, "Pivot: Revolution").Show()
    app.MainLoop()



and the following code in menu.py:
##Pivot: Revolution is a stickfigure Animator designed to allow simplicity when animating.
##Copyright (C) 2011  Cody Dostal <CodDosta@uat.edu>

##This program is free software: you can redistribute it and/or modify
##it under the terms of the GNU Affero General Public License as
##published by the Free Software Foundation, either version 3 of the
##License, or (at your option) any later version.
##
##This program 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 Affero General Public License for more details.
##
##You should have received a copy of the GNU Affero General Public License
##along with this program.  If not, see <http://www.gnu.org/licenses/>.

from wx import * 
def menu(self):
    # Creating the menubar
    menuBar = wx.MenuBar()
    
    # Creating the file menu 
    filemenu = wx.Menu()
    newWindow = filemenu.Append(wx.ID_NEW, "&New", "Open a new window.")
    openFile = filemenu.Append(wx.ID_OPEN, "O&pen", "Open a file.")
    saveFile = filemenu.Append(wx.ID_SAVE, "S&ave", "Save a file.")
    filemenu.AppendSeparator()
    exitProgram = filemenu.Append(wx.ID_EXIT, "E&xit", "Exit the program.")
    
    # Creating the help menu
    helpmenu = wx.Menu()
    aboutDlg = helpmenu.Append(wx.ID_ABOUT, "&About", "About the Program")
    helpDlg = helpmenu.Append(wx.ID_HELP, "&Help", "Get help with this program.")
    helpmenu.AppendSeparator()
    updateDlg = helpmenu.Append(wx.ID_FILE1, "Check for &Updates...", "Check for Updates to Pivot: Revolution")
    
    # Creating the Options Menu
    optionsmenu = wx.Menu()
    canvasSize = optionsmenu.Append(wx.ID_FILE9, "Canvas Size", "Set the size of the animation area.")
    
    menuBar.Append(filemenu, "&File")
    menuBar.Append(optionsmenu, "&Options")
    menuBar.Append(helpmenu, "&Help")
    self.SetMenuBar(menuBar)

    self.Bind(wx.EVT_MENU, self.exitmenu, exitProgram)
    self.Bind(wx.EVT_MENU, self.newWindow, newWindow)
    self.Bind(wx.EVT_MENU, self.openFile, openFile)
    self.Bind(wx.EVT_MENU, self.saveFile, saveFile)
    self.Bind(wx.EVT_MENU, self.aboutDlg, aboutDlg)
    self.Bind(wx.EVT_MENU, self.helpDlg, helpDlg)
    self.Bind(wx.EVT_MENU, self.updateDlg, updateDlg)
    self.Bind(wx.EVT_MENU, self.canvasSize, canvasSize)


Was This Post Helpful? 0
  • +
  • -

#12 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Importing external menu into tkinter python program

Posted 28 March 2011 - 06:35 AM

Great job dude. Sorry I didn't get back to you, I wasn't online all weekend.
Was This Post Helpful? 0
  • +
  • -

#13 CodyD  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 75
  • Joined: 19-August 10

Re: Importing external menu into tkinter python program

Posted 28 March 2011 - 07:42 AM

It's all good. I find it more fun to learn about it myself than not, but your help has definitely been welcome :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1