Rich Shepard wrote:
I have derived a class from wx.Dialog that allows the user to enter text
strings for each of four variables. The dialog box examples I've found all
print a message that "OK" was selected, but I want the values of each of
these four variables.
Are all the variables available for use when the "OK" button is selected?
As long as you have the instance around, you should be able to access its attributes and methods.
Do I declare them global so I can use them in a different class in the same
module?
ouch! no.
Is there an example I can see that shows how this is correctly done?
Here is a simple one that should make it clear:
class MyCheckDialog(wx.Dialog):
def __init__(self, Choices):
wx.Dialog.__init__(self, None, -1, 'wxDialog')
self.Choices = Choices
self.clb = wx.CheckListBox(self, -1, wx.DefaultPosition, wx.DefaultSize, self.Choices)
ok = wx.Button(self, wx.ID_OK, 'Ok')
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.clb, 1, wx.EXPAND|wx.ALL, 5)
sizer.Add(ok, 0, wx.ALIGN_RIGHT|wx.ALL^wx.TOP, 5)
self.SetSizer(sizer)
#self.Fit()
self.Center() # make it come up on the center of the screen
def GetChecked(self):
Checked =
for (index, item) in enumerate(self.Choices):
if self.clb.IsChecked(index):
Checked.append(item)
return Checked
## And to use it:
a = wx.App()
myd = MyCheckDialog(['check', 'list', 'box', 'another'])
if myd.ShowModal() != wx.ID_OK:
exit(1)
else:
print "You checked:", myd.GetChecked()
If you put all that in a file and run it, you'll see how it works
···
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov