object has no attribute 'OnPressEnter'

I am trying to get a dialog box working using wxpython under Centos 6.

Here is my initialzation code which give the error: object has no attribute ‘OnPressEnter’

I am new at this so be kind :slight_smile:

Ideas as to what I am doing wrong?

Thanx alot!

def initialize(self):
sizer = wx.GridBagSizer()

self.entry = wx.TextCtrl(self,-1,value=u"Enter File Name")
sizer.Add(self.entry,(0,0),(1,1),wx.EXPAND)
···

###########################

next lines cause error

AttributeError: object has no attribute ‘OnPressEnter’

self.Bind(wx.EVT_TEXT_ENTER,self.OnPressEnter,self.entry)

button = wx.Button(self,-1,label="Click me!")
sizer.Add(button, (0,1))

###########################

next line cause errors

self.Bind(wx.EVT_BUTTON, self.OnButtonClick, button)

self.label = wx.StaticText(self,-1,label=u'Hello !')
self.label.SetBackgroundColour(wx.BLACK)
self.label.SetForegroundColour(wx.RED)
sizer.Add(self.label,(1,0),(1,2),wx.EXPAND )
self.Refresh()

sizer.AddGrowableCol(0)
self.SetSizerAndFit(sizer)
self.SetSizeHints(-1,self.GetSize().y,-1,self.GetSize().y );
self.Show(True)

John,
you can bind to button methods you have to add them, usually as a member of the same class.
Gadget/Steve

···

On 12/07/14 23:20, John wrote:

    I am trying to get a dialog box working using

wxpython under Centos 6.

    Here is my initialzation code which give the error: object has

no attribute ‘OnPressEnter’

    I am new at this so be kind :-)



    Ideas as to what I am doing wrong?



    Thanx alot!

def initialize(self):

          sizer = wx.GridBagSizer()



          self.entry = wx.TextCtrl(self,-1,value=u"Enter File Name")

          sizer.Add(self.entry,(0,0),(1,1),wx.EXPAND)



      ###########################

      #### next  lines cause error

      #### AttributeError:  object has no attribute 'OnPressEnter'

          self.Bind(wx.EVT_TEXT_ENTER,self.OnPressEnter,self.entry)





          button = wx.Button(self,-1,label="Click me!")

          sizer.Add(button, (0,1))

      ###########################

      #### next line cause errors

      ####

          self.Bind(wx.EVT_BUTTON, self.OnButtonClick, button)



          self.label = wx.StaticText(self,-1,label=u'Hello !')

          self.label.SetBackgroundColour(wx.BLACK)

          self.label.SetForegroundColour(wx.RED)

          sizer.Add(self.label,(1,0),(1,2),wx.EXPAND )

          self.Refresh()



          sizer.AddGrowableCol(0)

          self.SetSizerAndFit(sizer)

          self.SetSizeHints(-1,self.GetSize().y,-1,self.GetSize().y

);

          self.Show(True)

  You received this message because you are subscribed to the Google

Groups “wxPython-users” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to wxpython-users+unsubscribe@googlegroups.com.

  For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

Beforewrite

Hi John,

···

On 7/13/2014 0:20, John wrote:

I am trying to get a dialog box working using wxpython under Centos 6.

Here is my initialzation code which give the error: object has no attribute 'OnPressEnter'

I am new at this so be kind :slight_smile:

Ideas as to what I am doing wrong?

The error "Object has no attribute" points out that "OnPressEnter" does not exist for the object, have you defined this event handler? Have you written it exactly the same?

Werner

Hi Werner,

Might have been a typo - I moved the code higher in the class code and then the error stopped.

The error stops but when I press enter, it does not execute my code.

Here is test code I am using:

#!/usr/bin/python

-- coding: iso-8859-1 --

try:
import wx
except ImportError:
raise ImportError,“The wxPython module is required to run this program”

class simpleapp_wx(wx.Frame):
def init(self,parent,id,title):
wx.Frame.init(self,parent,id,title)
self.parent = parent
self.initialize()

def initialize(self):
    sizer = wx.GridBagSizer()

    self.entry = wx.TextCtrl(self,-1,value=u"Enter text here.")
    sizer.Add(self.entry,(0,0),(1,1),wx.EXPAND)
    self.Bind(wx.EVT_TEXT_ENTER, self.OnPressEnter, self.entry)

    button = wx.Button(self,-1,label="Click me !")
    sizer.Add(button, (0,1))
    self.Bind(wx.EVT_BUTTON, self.OnButtonClick, button)

    self.label = wx.StaticText(self,-1,label=u'Hello !')
    self.label.SetBackgroundColour(wx.BLUE)
    self.label.SetForegroundColour(wx.WHITE)
    sizer.Add( self.label, (1,0),(1,2), wx.EXPAND )

    sizer.AddGrowableCol(0)
    self.SetSizerAndFit(sizer)
    self.SetSizeHints(-1,self.GetSize().y,-1,self.GetSize().y );
    self.Show(True)

def OnButtonClick(self,event):
    print "You clicked the button !"

def OnPressEnter(self,event):
    print "You pressed enter !"

if name == “main”:
app = wx.App()
frame = simpleapp_wx(None,-1,‘my application’)
app.MainLoop()

The button click works but when I press Enter nothing happens.

Thoughts??

Thanks,

John

···

On Sunday, July 13, 2014 2:19:59 AM UTC-6, werner wrote:

Hi John,

On 7/13/2014 0:20, John wrote:

I am trying to get a dialog box working using wxpython under Centos 6.

Here is my initialzation code which give the error: object has no
attribute ‘OnPressEnter’

I am new at this so be kind :slight_smile:

Ideas as to what I am doing wrong?

The error “Object has no attribute” points out that “OnPressEnter” does
not exist for the object, have you defined this event handler? Have you
written it exactly the same?

Werner

Hi Werner,

Attached is the code…

-John

wx_test.py (1.35 KB)

···

On Sunday, July 13, 2014 3:49:50 PM UTC-6, John wrote:

Hi Werner,

Might have been a typo - I moved the code higher in the class code and then the error stopped.

The error stops but when I press enter, it does not execute my code.

Here is test code I am using:

#!/usr/bin/python

-- coding: iso-8859-1 --

try:
import wx
except ImportError:
raise ImportError,“The wxPython module is required to run this program”

class simpleapp_wx(wx.Frame):
def init(self,parent,id,title):
wx.Frame.init(self,parent,id,title)
self.parent = parent
self.initialize()

def initialize(self):
    sizer = wx.GridBagSizer()

    self.entry = wx.TextCtrl(self,-1,value=u"Enter text here.")
    sizer.Add(self.entry,(0,0),(1,1),wx.EXPAND)
    self.Bind(wx.EVT_TEXT_ENTER, self.OnPressEnter, self.entry)

    button = wx.Button(self,-1,label="Click me !")
    sizer.Add(button, (0,1))
    self.Bind(wx.EVT_BUTTON, self.OnButtonClick, button)


    self.label = wx.StaticText(self,-1,label=u'Hello !')
    self.label.SetBackgroundColour(wx.BLUE)
    self.label.SetForegroundColour(wx.WHITE)
    sizer.Add( self.label, (1,0),(1,2), wx.EXPAND )

    sizer.AddGrowableCol(0)
    self.SetSizerAndFit(sizer)
    self.SetSizeHints(-1,self.GetSize().y,-1,self.GetSize().y );
    self.Show(True)

def OnButtonClick(self,event):
    print "You clicked the button !"

def OnPressEnter(self,event):
    print "You pressed enter !"

if name == “main”:
app = wx.App()
frame = simpleapp_wx(None,-1,‘my application’)
app.MainLoop()

The button click works but when I press Enter nothing happens.

Thoughts??

Thanks,

John

On Sunday, July 13, 2014 2:19:59 AM UTC-6, werner wrote:

Hi John,

On 7/13/2014 0:20, John wrote:

I am trying to get a dialog box working using wxpython under Centos 6.

Here is my initialzation code which give the error: object has no
attribute ‘OnPressEnter’

I am new at this so be kind :slight_smile:

Ideas as to what I am doing wrong?

The error “Object has no attribute” points out that “OnPressEnter” does
not exist for the object, have you defined this event handler? Have you
written it exactly the same?

Werner

Hello John, you need to set the style TE_PROCESS_ENTER for the TextCtrl to recieve events for the Enter-Key.

self.entry = wx.TextCtrl(self,-1,value=u"Enter text here.",style=wx.TE_PROCESS_ENTER)

···

Am Sonntag, 13. Juli 2014 23:49:50 UTC+2 schrieb John:

The button click works but when I press Enter nothing happens.

Hi Torsten,

You are a magician.

Thanks so much!!

-John

···

On Sunday, July 13, 2014 5:32:57 PM UTC-6, Torsten wrote:

Am Sonntag, 13. Juli 2014 23:49:50 UTC+2 schrieb John:

The button click works but when I press Enter nothing happens.

Hello John, you need to set the style TE_PROCESS_ENTER for the TextCtrl to recieve events for the Enter-Key.

self.entry = wx.TextCtrl(self,-1,value=u"Enter text here.",style=wx.TE_PROCESS_ENTER)