471,342 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Binding wxPython events to buttons

2
This is a problem faced by one of my friends. I have NO knowledge of Python but am just eager to help him.

He created a button using Python 2.4 and used event bindings using the id for the button in the format

self.Bind(wx.EVT_MENU, self.quit, id=102) (this is not from his code)

Now he migrated to Python 2.5 and for a certain button, he did the button (lets say A) click binding without the id.

But now he faces problems where if he clicks this button (A) a function bound to some other button is called. Could this have anything to do with the internal ids created for buttons ??

Please let me know if this query makes no sense because I have NO KNOWLEDGE about Python.
Oct 4 '07 #1
3 5630
bartonc
6,596 Expert 4TB
This is a problem faced by one of my friends. I have NO knowledge of Python but am just eager to help him.

He created a button using Python 2.4 and used event bindings using the id for the button in the format

self.Bind(wx.EVT_MENU, self.quit, id=102) (this is not from his code)

Now he migrated to Python 2.5 and for a certain button, he did the button (lets say A) click binding without the id.

But now he faces problems where if he clicks this button (A) a function bound to some other button is called. Could this have anything to do with the internal ids created for buttons ??

Please let me know if this query makes no sense because I have NO KNOWLEDGE about Python.
The Python version has nothing to do with this issue.
This is the old "self.bind vs button.bind" issue. Buttons are normally bound directly to their handlers. As in:
Expand|Select|Wrap|Line Numbers
  1. wxID_TRAILDATAVIEWERCOMMITBUTTON = wx.NewID()
  2.         self.CommitButton = wx.Button(id=wxID_TRAILDATAVIEWERCOMMITBUTTON,
  3.                label='Apply Changes',
  4.                name='CommitButton',
  5.                parent=self,
  6.                pos=wx.Point(20, 624),
  7.                size=wx.Size(184, 34),
  8.                style=0)
  9.         self.CommitButton.Bind(wx.EVT_BUTTON, self.OnCommitButton,
  10.                 id=wxID_TRAILDATAVIEWERCOMMITBUTTON)
I can post a link to an article that talks about these issues, if you like.

Note also that it is very bad practice to use literals in the ID argument. They may collide with IDs used internally.
Oct 4 '07 #2
swbi
2
The Python version has nothing to do with this issue.
This is the old "self.bind vs button.bind" issue. Buttons are normally bound directly to their handlers. As in:
Expand|Select|Wrap|Line Numbers
  1. wxID_TRAILDATAVIEWERCOMMITBUTTON = wx.NewID()
  2.         self.CommitButton = wx.Button(id=wxID_TRAILDATAVIEWERCOMMITBUTTON,
  3.                label='Apply Changes',
  4.                name='CommitButton',
  5.                parent=self,
  6.                pos=wx.Point(20, 624),
  7.                size=wx.Size(184, 34),
  8.                style=0)
  9.         self.CommitButton.Bind(wx.EVT_BUTTON, self.OnCommitButton,
  10.                 id=wxID_TRAILDATAVIEWERCOMMITBUTTON)
I can post a link to an article that talks about these issues, if you like.

Note also that it is very bad practice to use literals in the ID argument. They may collide with IDs used internally.

Thank you for your response. Can you please point me to the appropriate link that talks about such issues.
We are not using literals in our ID arguments. We are creating new IDs using wx.NewId() call. Can there still be clashes between the internal IDs and the ones used in the program.
Another thing to point about the code is that my friend is using a mixed approach of self.bind() and button.bind() . Could this be causing a problem ?
Oct 5 '07 #3
bartonc
6,596 Expert 4TB
Thank you for your response. Can you please point me to the appropriate link that talks about such issues.
We are not using literals in our ID arguments. We are creating new IDs using wx.NewId() call. Can there still be clashes between the internal IDs and the ones used in the program.
Another thing to point about the code is that my friend is using a mixed approach of self.bind() and button.bind() . Could this be causing a problem ?
This article in the Python Forum Articles section links to an in-depth article on this issue. I'm linking to the articles section here to make people aware of its existence.
Oct 5 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

15 posts views Thread by Grant Edwards | last post: by
8 posts views Thread by Erik Johnson | last post: by
6 posts views Thread by Robin Dunn | last post: by
reply views Thread by Robin Dunn | last post: by
2 posts views Thread by Kevin Walzer | last post: by
7 posts views Thread by Terry Carroll | last post: by

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.