0

我是 wxpython 的新手,所以我正在为此苦苦挣扎。我只想创建一个带有标签的按钮,当我按下按钮时,这个标签将显示到 textctrl 区域,例如手机,当你按下一个时,屏幕上显示的数字是一个!

import wx


class example(wx.Frame):

    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,' Title', size = (205,330))
        panel = wx.Panel(self, wx.ID_ANY)
        textctrl = wx.TextCtrl(panel, -1,("0"), pos=(10, 10),size=(170, 60))


        button=wx.Button(panel,label="1",pos=(100,210),size=(30,30))
        self.Bind(wx.EVT_BUTTON, self.OnButton, button)

    def OnButton (self,evt):
        label = evt.GetEventObject().GetLabel()


if __name__=='__main__':
    app=wx.PySimpleApp()
    frame=example(parent=None,id=-1)
    frame.Show()
    app.MainLoop()

谢谢

4

1 回答 1

0

您需要保留对控件的引用 - 然后您可以设置它们:

import wx

class example(wx.Frame):
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,' Title', size = (205,330))
        panel = wx.Panel(self, wx.ID_ANY)
        self.textctrl = wx.TextCtrl(panel, -1,(""), pos=(10, 10),size=(170, 60))
        self.button=wx.Button(panel,label="1",pos=(100,210),size=(30,30))
        self.Bind(wx.EVT_BUTTON, self.OnButton, self.button)
    def OnButton (self,evt):
        label = evt.GetEventObject().GetLabel()
        #self.textctrl.SetValue(label)
        self.textctrl.AppendText(label)


if __name__=='__main__':
    app=wx.PySimpleApp()
    frame=example(parent=None,id=-1)
    frame.Show()
    app.MainLoop()
于 2013-08-08T07:04:16.943 回答