Note that there are some explanatory texts on larger screens.

plurals
  1. POPython TypeError when using class (wx.Python)
    primarykey
    data
    text
    <p>This program is that wx.textctrl is written "clicked" when button is clicked. </p> <p>This code runs without error.</p> <pre><code>import wx class Mainwindow(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size=(300, 300)) panel = wx.Panel(self, -1) vbox = wx.BoxSizer(wx.VERTICAL) hbox1 = wx.BoxSizer(wx.HORIZONTAL) btn = wx.Button(panel, -1, 'OK', size=(70, 30)) btn.Bind(wx.EVT_BUTTON, self.click_btn) #line 12 hbox1.Add(btn, 0) vbox.Add(hbox1, 0) hbox2 = wx.BoxSizer(wx.HORIZONTAL) self.tc = wx.TextCtrl(panel, -1, style=wx.TE_MULTILINE) hbox2.Add(self.tc, 1, wx.EXPAND) vbox.Add(hbox2, 1, wx.EXPAND) panel.SetSizer(vbox) self.Centre() self.Show(True) def click_btn(self, event): #line 27 self.tc.WriteText("clicked\n") #line 28 if __name__=="__main__": app = wx.App() Mainwindow(None, -1, u"sample") app.MainLoop() </code></pre> <p>But if this code change in this way, it gets error. </p> <p>change to line 12.</p> <pre><code>btn.Bind(wx.EVT_BUTTON, Click_btn.click_btn) </code></pre> <p>change to line 27 and 28. </p> <pre><code>class Click_btn: def click_btn(self, event): self.tc.WriteText("clicked\n") </code></pre> <p>The error is: Typeerror: unbound method click_btn() must be called with Click_btn instance as first argument (got CommandEvent instance instead)</p> <p>I don't know how to cope with this error. </p> <p>*Postscript</p> <p>I read answer,and this code change. But it don't run...</p> <p>change to line 12.</p> <pre><code>button = Click_btn() btn.Bind(wx.EVT_BUTTON, button.click_btn) </code></pre> <p>change to line 27 and 28.</p> <pre><code>class Click_btn(Mainwindow): def click_btn(self, event): Mainwindow.tc.WriteText("clicked\n") </code></pre> <p>Please teach point that I should change.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload