473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Linking onClick event to other controls on the Frame

Hello,
I've created a simple form with 2 radio boxes, 2 text boxes and a
button.
When I click the button, I'd like to write each "choice" to a text
file.
I can't figure out how to "link" the onClick event to the other 4
controls.
Any help would be much appreciated!
R.D. Harles

import wx, sys

class Form1(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)

# Create button
self.button =wx.Button(self, 50, "GO!", wx.Point(20, 200))
wx.EVT_BUTTON(self, 50, self.OnClick)

## First name
# Edit control
self.lblname = wx.StaticText(self, -1, "First Name
:",wx.Point(20,50))
self.editname = wx.TextCtrl(self, 10, "", wx.Point(90, 50),
wx.Size(100,-1))
wx.EVT_TEXT(self, 10, self.EvtText)

## Last Name
# Edit control
self.lblname = wx.StaticText(self, -1, "Last Name
:",wx.Point(20,75))
self.editname = wx.TextCtrl(self, 20, "", wx.Point(90, 75),
wx.Size(100,-1))
wx.EVT_TEXT(self, 20, self.EvtText)

# Radio Boxes
self.radioList = ['Employed', 'Unemployed']
rb = wx.RadioBox(self, 30, "Status:", wx.Point(20, 100),
wx.DefaultSize,
self.radioList, 2, wx.RA_SPECIFY_COLS)
wx.EVT_RADIOBOX(self, 30, self.EvtRadioBox)

# Radio Boxes
self.radioList = ['Married', 'Single']
rb = wx.RadioBox(self, 40, "Status:", wx.Point(20, 150),
wx.DefaultSize,
self.radioList, 2, wx.RA_SPECIFY_COLS)
wx.EVT_RADIOBOX(self, 40, self.EvtRadioBox)

# Text event
def EvtText(self, event):
print event.GetString()

# RadioBox event
def EvtRadioBox(self, event):
print event.GetId()

# Button event
def OnClick(self,event):

print "Writing job.cfg..."
file = open("job.cfg", "w")
file.write("")
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, " Questions")
Form1(frame,-1)
frame.Show(1)
app.MainLoop()

May 26 '06 #1
2 2199
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/

May 28 '06 #2
Hi Miki,
I appreciate you taking the time to figure out what I was trying to do.
This is exactly what I was looking for.
I plan on studing this code and looking at the wxpython demo as you
mentioned.
Thanks again!
R.D. Harles

May 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Arulraja | last post by:
Hello, I have created 2 custom server controls, The parent custom control contains multiple child custom controls. The Child control has a button on it. If I Click the button control, it...
1
by: Joel Barsotti | last post by:
Is there anything builtin to ASP.net that allows you to tie a text box to a button so when you press enter in the text box it emulates clicking a near by button. I've coded up some client side...
3
by: =?Utf-8?B?cml2YWxAbmV3c2dyb3Vwcy5ub3NwYW0=?= | last post by:
I've a situation where I'm creating controls programatically. I'm programatically creating table cells and rows. I've got an array of data, and I want to format the data on screen in rows of 4. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.