I'm trying to display a value on the status bar according to a position on a plot made on a panel. So I want to call the method SetStatusText with the value in a string. The instance of RefreshPanel is set within a frame called 'frame', which is an instance of a subclass MyFrame of wx.Frame in which the status bar is set. But when I left click in the plot on the panel I get

line 51, in OnLeftDown
frame.SetStatusText("%.1f kHz" % freqkhz)
AttributeError: 'builtin_function_or_method' object has no attribute 'SetStatusText'

class RefreshPanel(wx.Panel):
    def __init__(self, parent, id, pos, size):
        wx.Panel.__init__(self, parent, id, pos, size)

        
        global xaxis,yaxis,z
        
        
        
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown


    def OnLeftDown(self, event):
        """left mouse button is pressed"""
        pt = event.GetPosition()  # position tuple
        freqkhz = (600 - pt[1])/500.0/1000.0*(yaxis[-1]-yaxis[0])
        print "%.1f kHz" % freqkhz
        
        frame.SetStatusText("%.1f kHz" % freqkhz)

Line 6 looks strange. Use attributes not global variables.

Looks like frame would be global variable. Print also value of frame on line 17.

You can try the following, assuming frame is the parent of the panel.
In def __init__ of class RefreshPanel, add

self.parent = parent

Then, instead of frame.SetStatusText(), use self.parent.SetStatusText()

Excellent, it works! Thanks very much for your help with this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.