Linking onClick event to other controls on the Frame

Miki miki.tebeka at gmail.com
Sun May 28 12:47:48 CEST 2006


Hello Harles,

Please define "link" - is it bind event, get information from control,
...?
If I'm guessing the you want to the the value of each control then you
need to store a reference to this control and call the method that gets
the value of each control.
(GetValue() for most, GetStringSelection() for others ...)

Also I suggest you use sizers instead of hard coding the widgets
location.

My best suggestion however is that you download the wxPython demo and
view the examples over there.

See revised code below:

import wx
class Form1(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        sizer = wx.GridSizer(wx.VERTICAL)
        gsizer = wx.FlexGridSizer(2, 2)

        # First Name: _______
        gsizer.Add(wx.StaticText(self, -1, "First Name:"))
        self._first_name = wx.TextCtrl(self, -1, size=(100, -1))
        gsizer.Add(self._first_name, 0, wx.EXPAND)

        # Last Name: _______
        gsizer.Add(wx.StaticText(self, -1, "Last Name:"))
        self._last_name = wx.TextCtrl(self, -1, size=(100, -1))
        gsizer.Add(self._last_name, 0, wx.EXPAND)
        gsizer.AddGrowableCol(1)

        sizer.Add(gsizer, 1, wx.EXPAND)

        self._work_status = wx.RadioBox(self, -1, "Work Status",
                choices=["Employed", "Unemployed"])
        sizer.Add(self._work_status, 0, wx.EXPAND)

        self._martial_status = wx.RadioBox(self, -1, "Martial Status",
                choices=["Married", "Single"])
        sizer.Add(self._martial_status, 0, wx.EXPAND)

        b = wx.Button(self, -1, "GO!")
        self.Bind(wx.EVT_BUTTON, self.OnClick, b)
        sizer.Add(b)

        self.SetSizer(sizer)
        self.SetAutoLayout(1)
        sizer.Fit(self)

    # Button event
    def OnClick(self,event):
        fo = open("job.cfg", "w")
        print >> fo, "First Name:", self._first_name.GetValue()
        print >> fo, "Last Name:", self._last_name.GetValue()
        print >> fo, "Work Status:",
self._work_status.GetStringSelection()
        print >> fo, "Martial Status:",
self._martial_status.GetStringSelection()
        fo.close()

HTH,
Miki
http://pythonwise.blogspot.com/




More information about the Python-list mailing list