我是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()
由于
答案 0 :(得分: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()