python - How to get the button object created by CreateButtonSizer (or CreateSeparatedButtonSizer) in wxPython -


i feel should simple, can't find out there. have pretty simple dialog, 2 text controls. create ok/cancel buttons sizer using createseparatedbuttonsizer method.

the issue is, try enable/disable "ok" button based off of criteria on entries in text controls. in other words, until valid entries entered text controls, want ok button disabled. can't seem find on how reference button, , i'd rather not manually create buttons dialog remains platform 'agnostic.'

small sample code:

class mydialog(wx.dialog):     def __init__(self, parent, title):         wx.dialog.__init__(self, parent=parent, title=title)          # grid sizer text controls , labels:         grid = wx.gridbagsizer(2,2)          # add input fields:         grid.add(wx.statictext(self, label="field 1: "),pos=(0,0))         self.fld1 = wx.textctrl(self, value="", size=(70,-1))         grid.add(self.fld1, pos=(0,1))         grid.add(wx.statictext(self, label="field 2: "),pos=(1,0))         self.fld2 = wx.textctrl(self, value="", size=(70,-1))         grid.add(self.fld2, pos=(1,1))          # buttonsizer:         btns = self.createseparatedbuttonsizer(wx.ok|wx.cancel)          # lay out:         mainsizer = wx.boxsizer(wx.vertical)         mainsizer.add(grid, 1, wx.all|wx.expand)         mainsizer.add(btns, 0, wx.all|wx.expand)         self.setsizer(mainsizer)         self.fit() 

so, i'd bind method text controls, checks whether or not inputs valid. if are, ok button enabled, , if not, should disabled. there way this?

thanks!

the ok button has id wx.id_ok. can try wx.findwindowbyid(wx.id_ok, self) if you're trying find within mydialog class. if you're trying reference button outside of mydialog class, you'll want use instance of mydialog second parameter. ex.

dialog_instance = mydialog() ok_button = wx.findwindowbyid(wx.id_ok, dialog_instance) 

here's documentation on findwindowbyid http://xoomer.virgilio.it/infinity77/wxpython/wxfunctions.html#findwindowbyid


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -