Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8579603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:38:36+00:00 2026-06-11T20:38:36+00:00

How can I give a variable to a function when I bind something? As

  • 0

How can I give a variable to a function when I bind something? As a simple example:

def test(self):
    self.MyTextCtrl.Bind(wx.EVT_TEXT, self.something, AnyVariable)

def something(self, event, x)
    # do something
    print x

As you see, I want to give the value “AnyVariable” to the function “something” so that it will be used as the “x”. How can I do this? This example doesn’t work.

Edit:
@ Paul McNett:
Yeah, what I’m trying to do is more like:

def test(self):
    self.MyTextCtrl1.Bind(wx.EVT_TEXT, self.something, Variable1)
    self.MyTextCtrl2.Bind(wx.EVT_TEXT, self.something, Variable2)
    self.MyTextCtrl3.Bind(wx.EVT_TEXT, self.something, Variable3)

def something(self, event, x)
    # do something by including x

x=Variable1 when “MyTextCtrl1” is edited, x=Variable2 when “MyTextCtrl2” is edited and x=Variable3 when “MyTextCtrl3” is edited.

Of course I also could write 3 different functions (“def something1”, “def something2”, “def something3”) and bind them to “MyTextCtrl1”, “MyTextCtrl2” or “MyTextCtrl3”. But I thought it could be much easier when I use this variable instead 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:38:37+00:00Added an answer on June 11, 2026 at 8:38 pm

    One of the following approaches should do it:

    • Introduce a global variable (variable declaration outside the function scope at module level).

      x = None
      def test(self):
          self.MyTextCtrl.Bind(wx.EVT_TEXT, self.something)
      
      def something(self, event):
          global x
          x = ... # alter variable on event
      
    • Introduce a member variable of a class.

    • Furthermore wx.EVTHandler suggests anything as event handler that is callable. For this case I’ve written a simple class to hold one value (extendable for multiple values) and that implements a __call__ method. Interfering special methods is an advanced topic, for this case I’ve put together example code:

      import wx
      
      class TestFrame(wx.Frame):
          def __init__(self, *args, **kwargs):
              wx.Frame.__init__(self, None, -1, *args, **kwargs)
              sizer = wx.BoxSizer(wx.VERTICAL)
              self.SetSizer(sizer)
              b = wx.Button(self, -1, "Test")
              sizer.Add(b)
              b.Bind(wx.EVT_BUTTON, TestHandler("foo"))
              self.Show()
      
      class TestHandler:
          def __init__(self, value):
              self.value = value
      
          def __call__(self, event):
              print event
              print "My value is:", self.value
      
      if __name__ == "__main__":
          app = wx.App()
          TestFrame("")
          app.MainLoop()
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I train myself to give better variable and function names (any user-defined
who can give me a simple code , i want a simplest way to
Can anyone give me a clue, how to create/call function regular expression syntax in
can anyone give me an example on how to create Sessions and write data
The question In Javascript, how can an event handler function refer to members of
I need a function that can simulate the C++ for statement. I want something
I want to know that, can we able to give a variable instead of
Someone can give me short explanation how to create bitmap runtime using GDI/GDI+ and
Who can give me a link for the operator= of vector in MSDN? Why
I hope you can give me a hand on this. It's been bothering me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.