GetValue from TextCtrl by hitting a button

All i want to do is get the TextCtrl data when i hit the Co button.
I dont know why this doesnt work. I think i am missing something.
So i need some help

import wx

class Loud(wx.Frame):

  def __init__(self,parent,id,title):
    wx.Frame.__init__(self,parent,id,title,size=(300,200))

    txtu = wx.TextCtrl(self, -1 )

    btnco = wx.Button(self, -1,"Co",pos=(0,30))

    self.Bind(wx.EVT_BUTTON, self.OnCo(txtu.GetValue()), id =
btnco.GetId())

  def OnCo(self,event,txt):
    print txt

app = wx.App()
frame = Loud(None,-1,"Loud")
frame.Show()
app.MainLoop()

hi,

From: wxpython-users@googlegroups.com [mailto:wxpython-
users@googlegroups.com] On Behalf Of picon
Sent: Thursday, October 07, 2010 5:38 AM
To: wxPython-users
Subject: [wxPython-users] GetValue from TextCtrl by hitting a button

All i want to do is get the TextCtrl data when i hit the Co button.
I dont know why this doesnt work. I think i am missing something.
So i need some help

import wx

class Loud(wx.Frame):

  def __init__(self,parent,id,title):
    wx.Frame.__init__(self,parent,id,title,size=(300,200))

    txtu = wx.TextCtrl(self, -1 )

    btnco = wx.Button(self, -1,"Co",pos=(0,30))

    self.Bind(wx.EVT_BUTTON, self.OnCo(txtu.GetValue()), id =
btnco.GetId())

  def OnCo(self,event,txt):
    print txt

app = wx.App()
frame = Loud(None,-1,"Loud")
frame.Show()
app.MainLoop()

--
To unsubscribe, send email to wxPython-
users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

[alm>]

Minimum changes to make it go:

import wx

class Loud(wx.Frame):

    def __init__(self,parent,id,title):
  wx.Frame.__init__(self,parent,id,title,size=(300,200))

  self.txtu = wx.TextCtrl(self, -1 )

  btnco = wx.Button(self, -1,"Co",pos=(0,30))

  self.Bind(wx.EVT_BUTTON, self.OnCo, id = btnco.GetId() )

    def OnCo(self,event):

        txt = self.txtu.GetValue()
        print txt

app = wx.App()
frame = Loud(None,-1,"Loud")
frame.Show()
app.MainLoop()

···

-----Original Message-----

Thanks!

Python has its way.

···

2010/10/7 Al Mansur almansur@rusnam.org

hi,

-----Original Message-----

From: wxpython-users@googlegroups.com [mailto:wxpython-

users@googlegroups.com] On Behalf Of picon

Sent: Thursday, October 07, 2010 5:38 AM

To: wxPython-users

Subject: [wxPython-users] GetValue from TextCtrl by hitting a button

All i want to do is get the TextCtrl data when i hit the Co button.

I dont know why this doesnt work. I think i am missing something.

So i need some help

import wx

class Loud(wx.Frame):

  def __init__(self,parent,id,title):
          wx.Frame.__init__(self,parent,id,title,size=(300,200))
          txtu = wx.TextCtrl(self, -1 )
          btnco = wx.Button(self, -1,"Co",pos=(0,30))
          self.Bind(wx.EVT_BUTTON, self.OnCo(txtu.GetValue()), id =

btnco.GetId())

  def OnCo(self,event,txt):
          print txt

app = wx.App()

frame = Loud(None,-1,“Loud”)

frame.Show()

app.MainLoop()

To unsubscribe, send email to wxPython-

users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

[alm>]

Minimum changes to make it go:

import wx

class Loud(wx.Frame):

def __init__(self,parent,id,title):

    wx.Frame.__init__(self,parent,id,title,size=(300,200))

self.txtu = wx.TextCtrl(self, -1 )

    btnco = wx.Button(self, -1,"Co",pos=(0,30))

self.Bind(wx.EVT_BUTTON, self.OnCo, id = btnco.GetId() )

def OnCo(self,event):



    txt = self.txtu.GetValue()

print txt

app = wx.App()

frame = Loud(None,-1,“Loud”)

frame.Show()

app.MainLoop()

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Well, you should understand what you did wrong.

self.Bind(wx.EVT_BUTTON, self.OnCo, id = btnco.GetId() )

Bind takes a function *pointer*. That is, a reference to a function
  • without any braces. Your code is “calling” self.OnCo and passing
    its return value as the function to bind to. In the fixed code, you
    can see how self.OnCo itself is used, not self.OnCo(blah…)
···

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

-- Steven Sproat, BSc

http://www.whyteboard.org/