wxpython
i cant figure out the problem. it says that the global neme 'panel' is not defined.
Traceback (most recent call last):
File "C:\Users\Daniel\Desktop\Duffan Teorem", line 34, in clickbutton
wx.StaticText(panel,-1,media,pos=(150,240))
NameError: global name 'panel' is not defined

could someone please help me to figure tha problem out? Thanks in Advance


import wx
class duff(wx.Frame):

def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Duffan Formula', size=(400,300))
panel=wx.Panel(self,-1)

g=wx.StaticText(panel,-1,"________________________________________________________",pos=(10,65))
z=wx.StaticText(panel,-1,"Welcome to Duffan Formula!!",pos=(10,10))
r=wx.StaticText(panel,-1,"Here you can discover the score of any girl you are looking for.",pos=(10,30))
q=wx.StaticText(panel,-1,"Use it, with Knowledge!",pos=(10,50))
a=wx.StaticText(panel,-1,"What`s her name?",pos=(10,110))
b=wx.StaticText(panel,-1,"What`s her beauty score?",pos=(10,150))
c=wx.StaticText(panel,-1,"What`s her body score?",pos=(10,190))
average=wx.StaticText(panel,-1,"Average: ", pos=(80,222.5)).SetForegroundColour('blue')

self.one=wx.TextCtrl(panel,-1,'Enter name',pos=(110,108),size=(80,20))
self.two=wx.SpinCtrl(panel,-1,'1',pos=(150,148),size=(60,20),min=0,max=100)
self.three=wx.SpinCtrl(panel,-1,'1',pos=(130,188),size=(60,20),min=0,max=100)
wx.StaticBox(panel,-1,'Personal Info', (5,90),size=(250,160))


ae=wx.Button(panel,label="Done",pos=(10,220),size=(60,20))
self.Bind(wx.EVT_BUTTON,self.clickbutton,ae)
self.Centre()
self.Show(True)

def clickbutton(self,event):
s1=self.two.GetValue()
s2=self.three.GetValue()
media = s1

if 0<=media<=100:
wx.StaticText(panel,-1,media,pos=(150,240))

if __name__=='__main__':
app=wx.PySimpleApp()
frame=duff(parent=None,id=-1)
frame.Show()
app.MainLoop()

Recommended Answers

All 2 Replies

Use code tag next time you post.

import wx
class duff(wx.Frame):

    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,wx.ID_ANY,'Duffan Formula', size=(400,300)) #wx.ID_ANY
        self.panel = wx.Panel(self) #self.panel

        #self.panel on all
        g=wx.StaticText(self.panel,-1,"________________________________________________________",pos=(10,65))
        z=wx.StaticText(self.panel,-1,"Welcome to Duffan Formula!!",pos=(10,10))
        r=wx.StaticText(self.panel,-1,"Here you can discover the score of any girl you are looking for.",pos=(10,30))
        q=wx.StaticText(self.panel,-1,"Use it, with Knowledge!",pos=(10,50))
        a=wx.StaticText(self.panel,-1,"What`s her name?",pos=(10,110))
        b=wx.StaticText(self.panel,-1,"What`s her beauty score?",pos=(10,150))
        c=wx.StaticText(self.panel,-1,"What`s her body score?",pos=(10,190))
        average=wx.StaticText(self.panel,-1,"Average: ", pos=(80,222.5)).SetForegroundColour('blue')

        self.one=wx.TextCtrl(self.panel,-1,'Enter name',pos=(110,108),size=(80,20))
        self.two=wx.SpinCtrl(self.panel,-1,'1',pos=(150,148),size=(60,20),min=0,max=100)
        self.three=wx.SpinCtrl(self.panel,-1,'1',pos=(130,188),size=(60,20),min=0,max=100)
        wx.StaticBox(self.panel,-1,'Personal Info', (5,90),size=(250,160))


        ae=wx.Button(self.panel,label="Done",pos=(10,220),size=(60,20))
        self.Bind(wx.EVT_BUTTON,self.clickbutton,ae)
        self.Centre()
        self.Show(True)

    def clickbutton(self,event):
        '''
        Now this method can use self.panel
        Without self method can not use panel
        '''
        s1=self.two.GetValue()
        s2=self.three.GetValue()
        media = s1
        if  0<=media<=100:
            wx.StaticText(self.panel,-1, str(media) ,pos=(135,222)) #str(media)

if __name__=='__main__':
    app=wx.PySimpleApp()
    frame=duff(parent=None,id=-1)
    frame.Show()
    app.MainLoop()
commented: sharp eye +13

thhhhaank youu verryy muchhhhhhhhhh!!!

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.