I am new to python and am making a program with the wxpython module and no matter what I try I get a NameError: global name 'outp' is not defined?? Can someone help?
Here is the code, it is fairly complex:

import wx
class jake(wx.Frame):
    def func1(self,event):
        global foo
        foo+="1"
        global outp
        outp.append(1)
        outp=str(outp.strip("[").strip("]"))
    def func2(self,event):
        pass
    def func3(self,event):
        pass
    def func4(self,event):
        pass
    def func5(self,event):
        pass
    def func6(self,event):
        pass
    def func7(self,event):
        pass
    def func8(self,event):
        pass
    def func9(self,event):
        pass
    def func0(self,event):
        pass
    def decimalfunc(self,event):
        pass
    def infofunc(self,event):
        pass
    def withdraw(self,event):
        pass
    def deposit(self,event):
        pass
    def showbalance(self,event):
        pass
    def showstatus(self,event):
        pass
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,'Virtual Bank', size=(500,550))
        panel=wx.Panel(self)
        button1=wx.Button(panel,label="1",pos=(10,100),size=(75,75))
        button2=wx.Button(panel,label="2",pos=(110,100),size=(75,75))
        button3=wx.Button(panel,label="3",pos=(210,100),size=(75,75))
        button4=wx.Button(panel,label="4",pos=(10,200),size=(75,75))
        button5=wx.Button(panel,label="5",pos=(110,200),size=(75,75))
        button6=wx.Button(panel,label="6",pos=(210,200),size=(75,75))
        button7=wx.Button(panel,label="7",pos=(10,300),size=(75,75))
        button8=wx.Button(panel,label="8",pos=(110,300),size=(75,75))
        button9=wx.Button(panel,label="9",pos=(210,300),size=(75,75))
        button0=wx.Button(panel,label="0",pos=(10,400),size=(75,75))
        decimal=wx.Button(panel,label=".",pos=(110,400),size=(75,75))
        info=wx.Button(panel,label="INFO",pos=(210,400),size=(75,75))
        withdraw=wx.Button(panel,label="WITHDRAW",pos=(330,100),size=(130,75))
        deposit=wx.Button(panel,label="DEPOSIT",pos=(330,200),size=(130,75))
        balance=wx.Button(panel,label="BALANCE",pos=(330,300),size=(130,75))
        status=wx.Button(panel,label="STATUS",pos=(330,400),size=(130,75))
        self.Bind(wx.EVT_BUTTON, self.func1, button1)
        self.Bind(wx.EVT_BUTTON, self.func2, button2)
        self.Bind(wx.EVT_BUTTON, self.func3, button3)
        self.Bind(wx.EVT_BUTTON, self.func4, button4)
        self.Bind(wx.EVT_BUTTON, self.func5, button5)
        self.Bind(wx.EVT_BUTTON, self.func6, button6)
        self.Bind(wx.EVT_BUTTON, self.func7, button7)
        self.Bind(wx.EVT_BUTTON, self.func8, button8)
        self.Bind(wx.EVT_BUTTON, self.func9, button9)
        self.Bind(wx.EVT_BUTTON, self.func0, button0)
        self.Bind(wx.EVT_BUTTON, self.decimalfunc, decimal)
        self.Bind(wx.EVT_BUTTON, self.infofunc, info)
        self.Bind(wx.EVT_BUTTON, self.withdraw, withdraw)
        self.Bind(wx.EVT_BUTTON, self.deposit, deposit)
        self.Bind(wx.EVT_BUTTON, self.showbalance, balance)
        self.Bind(wx.EVT_BUTTON, self.showstatus, status)
        wx.StaticText(panel,-1,outp,(10,45))
        wx.StaticText(panel,-1,"Welcome To VirtualBank!",(180,20))
        wx.StaticText(panel,-1,"$",(10,40))
        
if __name__=='__main__':
    app=wx.PySimpleApp()
    frame=jake(parent=None,id=-1)
    frame.Show()
    app.MainLoop()

Use instance variables (self.) instead of global variables. Also, you can clean the program up by combining all of the number buttons into one for() loop and pass the number to a common function.

import wx
from functools import partial

class jake(wx.Frame):
    def __init__(self,parent,id):
        self.foo=""
        self.outp=0
        wx.Frame.__init__(self,parent,id,'Virtual Bank', size=(500,550))
        panel=wx.Panel(self)

        ## you can add in 4-->decimal buttons
        for button in (("1", 10, 100), ("2", 110, 100), ("3", 210,100)):
            this_button=wx.Button(panel,label=button[0],
                             pos=(button[1],button[2]),size=(75,75))
            self.Bind(wx.EVT_BUTTON, partial(self.func1, num=button[0]), 
                             this_button)

        info=wx.Button(panel,label="INFO",pos=(210,400),size=(75,75))
        withdraw=wx.Button(panel,label="WITHDRAW",pos=(330,100),size=(130,75))
        deposit=wx.Button(panel,label="DEPOSIT",pos=(330,200),size=(130,75))
        balance=wx.Button(panel,label="BALANCE",pos=(330,300),size=(130,75))
        status=wx.Button(panel,label="STATUS",pos=(330,400),size=(130,75))
        self.Bind(wx.EVT_BUTTON, self.decimalfunc, decimal)
        self.Bind(wx.EVT_BUTTON, self.infofunc, info)
        self.Bind(wx.EVT_BUTTON, self.withdraw, withdraw)
        self.Bind(wx.EVT_BUTTON, self.deposit, deposit)
        self.Bind(wx.EVT_BUTTON, self.showbalance, balance)
        self.Bind(wx.EVT_BUTTON, self.showstatus, status)
        wx.StaticText(panel,-1,str(self.outp),(10,45))
        wx.StaticText(panel,-1,"Welcome To VirtualBank!",(180,20))
        wx.StaticText(panel,-1,"$",(10,40))

    def func1(self, event, num):
        self.foo+=num
        self.outp+=1
        print num, "button pressed and total input is now", self.foo
    def decimalfunc(self,event):
        pass
    def infofunc(self,event):
        pass
    def withdraw(self,event):
        pass
    def deposit(self,event):
        pass
    def showbalance(self,event):
        pass
    def showstatus(self,event):
        pass
        
if __name__=='__main__':
    app=wx.PySimpleApp()
    frame=jake(parent=None,id=-1)
    frame.Show()
    app.MainLoop()
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.