473,668 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(s elf, 50, self.OnClick)

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

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

# Radio Boxes
self.radioList = ['Employed', 'Unemployed']
rb = wx.RadioBox(sel f, 30, "Status:", wx.Point(20, 100),
wx.DefaultSize,
self.radioList, 2, wx.RA_SPECIFY_C OLS)
wx.EVT_RADIOBOX (self, 30, self.EvtRadioBo x)

# Radio Boxes
self.radioList = ['Married', 'Single']
rb = wx.RadioBox(sel f, 40, "Status:", wx.Point(20, 150),
wx.DefaultSize,
self.radioList, 2, wx.RA_SPECIFY_C OLS)
wx.EVT_RADIOBOX (self, 40, self.EvtRadioBo x)

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

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

# Button event
def OnClick(self,ev ent):

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 2223
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, GetStringSelect ion() 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.FlexGridSize r(2, 2)

# First Name: _______
gsizer.Add(wx.S taticText(self, -1, "First Name:"))
self._first_nam e = wx.TextCtrl(sel f, -1, size=(100, -1))
gsizer.Add(self ._first_name, 0, wx.EXPAND)

# Last Name: _______
gsizer.Add(wx.S taticText(self, -1, "Last Name:"))
self._last_name = wx.TextCtrl(sel f, -1, size=(100, -1))
gsizer.Add(self ._last_name, 0, wx.EXPAND)
gsizer.AddGrowa bleCol(1)

sizer.Add(gsize r, 1, wx.EXPAND)

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

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

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

self.SetSizer(s izer)
self.SetAutoLay out(1)
sizer.Fit(self)

# Button event
def OnClick(self,ev ent):
fo = open("job.cfg", "w")
print >> fo, "First Name:", self._first_nam e.GetValue()
print >> fo, "Last Name:", self._last_name .GetValue()
print >> fo, "Work Status:",
self._work_stat us.GetStringSel ection()
print >> fo, "Martial Status:",
self._martial_s tatus.GetString Selection()
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
7716
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 calls the Parent controls CreateChildControls() method before calling the child control's button click event. Because of this behaviour, I am not getting the changes I made in the
1
1611
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 javascript that does this, but it fails when their is a validator monitoring the text box (in firefox, but that's 10% of my visitors).
3
1454
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. I get my array, calculate how many complete rows I need. Then for each of the complete rows, I format a cell for the data in that array element. When I've completed a row, I add it to my table. If I have a remainder, I do that at the end. ...
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8382
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8586
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7405
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1787
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.