wxPython: need return value from wxFrame
Cliff Wells
logiplex at qwest.net
Fri Aug 22 16:56:36 EDT 2003
On Fri, 2003-08-22 at 12:27, Mirko Koenig wrote:
> On Fri, 22 Aug 2003 00:28:23 +0200, Cliff Wells wrote:
>
> > On Thu, 2003-08-21 at 15:17, Mirko Koenig wrote:
> >> I have a frame where you can select/add/delte etc a customer address.
> >> It is included in an wxApp to have a stand alone customer addressbook.
> >>
> >> Now i wrote a invoice application. I added a button to add a address to
> >> the invoice. I want the customer addressbook to be open by clicking on
> >> that button. No problem. So far so good.
> >>
> >> But i want the addressbook frame to return the selected address as a
> >> tuple, list or dict. I don't have any idea how to do that.
> >>
> >> I can show() the frame from within the invoice code but show doesn't
> >> return a value.
> >
> > Use a wxDialog instead.
> >
>
> But how to return a list or tuple. All i can see is that a dialog returns
> a int value
Try something like this:
import wx
class MyDialog(wx.Dialog):
def __init__(self, parent, id, title = "Test"):
wx.Dialog.__init__(self, parent, id, title)
sizer = wx.BoxSizer(wx.VERTICAL)
self.text = {}
for t in ['1', '2', '3']:
self.text[t] = wx.TextCtrl(self, -1, "")
sizer.Add(self.text[t], 1, wx.ALIGN_CENTRE|wx.ALL, 5)
btn = wx.Button(self, wx.ID_OK, " OK ")
sizer.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
btn = wx.Button(self, wx.ID_CANCEL, " Cancel ")
sizer.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
self.SetSizer(sizer)
self.SetAutoLayout(True)
sizer.Fit(self)
def GetValue(self):
retval = {}
for t in self.text:
retval[t] = self.text[t].GetValue()
return retval
app = wx.PySimpleApp()
dlg = MyDialog(None, -1)
retval = dlg.ShowModal()
if retval == wx.ID_OK:
print dlg.GetValue()
dlg.Destroy()
app.MainLoop()
>
> Mirko Koenig
--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 (800) 735-0555
More information about the Python-list
mailing list