Not sure if this is the proper way to post code and question, I am
registered.
I use the book "wxPython IN ACTION" and learn by adapting some of the
example code.
I attempted to try to use a GridSizer and most of it works with the
exception noted at the bottom
of the included code. I removed a lot of existing code to get this down to
just the error. Hope I am posting correctly and get some answer. Thanks.
#!/usr/bin/env python
''' experimental code : XXXGasChkGrid.py '''
import wx
class GridSizerFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "GasChkGrid.py",pos=(200,100))
#calculated MPG
mpgLbl=wx.StaticText(self,-1,"MPG:")
mpg=wx.TextCtrl(self,-1,"",size=(80,20))
#Buttons
button1=wx.Button(self,-1,"Calculate")
button2=wx.Button(self,-1,"button2")
#button Event(s)
self.Bind(wx.EVT_BUTTON, self.OnClick,button2)
#create sizer
sizer = wx.GridSizer(rows=12, cols=2,hgap=5,vgap=5)
# add widgets to sizer
sizer.Add(mpgLbl,0,wx.ALIGN_RIGHT)
sizer.Add(mpg,0,0)
#add button(s)
sizer.Add(button1,0,0)
sizer.Add(button2,0,0)
self.SetSizer(sizer)
self.Fit()
self.Show() #redundit? see line 67
mpg.SetValue("123") #this is just testing, verify can change
text....
def OnClick(self,event):
print 'OK' # <===this works as expected.
mpg.SetValue("Clicked") #<=== gives error
app = wx.PySimpleApp()
GridSizerFrame().Show()
app.MainLoop()
''' Traceback (most recent call last):
File "XXXGasChkGrid.py", line 33, in OnClick
mpg.SetValue("Clicked") #<=== gives error
NameError: global name 'mpg' is not defined
'''
···
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Simple-wxPython-code-with-error-tp5720796.html
Sent from the wxPython-users mailing list archive at Nabble.com.