python - how to control a function of TextCtrl as dynamic in wxpython? -
i'm wxpython user. have question how control textctrl function. want build program if click button, textctrl's value changed. source code followed.
#!/usr/bin/python import wx class tom(wx.dialog): def __init__(self, parent, id, title): wx.dialog.__init__(self, parent, id, title, wx.defaultposition, wx.size(400, 420)) panel = wx.panel(self, -1) vbox = wx.boxsizer(wx.horizontal) self.write = wx.textctrl(panel, -1, style=wx.te_multiline, value=self.message) button_send = wx.button(panel, 1, label='b'+'1', 'send') vbox.add(self.write, 1, wx.expand | wx.top | wx.right | wx.left | wx.bottom, 15) vbox.add(button_send, 0, wx.align_center | wx.top | wx.bottom, 20) self.bind(wx.evt_button, self.onsend, id=1) panel.setsizer(vbox) self.centre() def onsend(self, event): b=event.geteventobject().getlabel() if b.endswith('1'): self.message = "sss" self.setwrite(self.message) class myapp(wx.app): def oninit(self): frame = tom(none, -1, 'tom') frame.showmodal() frame.destroy() return true app = myapp(0) app.mainloop()
if know solution please comment me. you.
use self.write.setvalue()
altered run using python-gtk3.0
#!/usr/bin/python import wx class tom(wx.dialog): def __init__(self, parent, id, title): wx.dialog.__init__(self, parent, id, title, wx.defaultposition, wx.size(400, 420)) panel = wx.panel(self, -1) vbox = wx.boxsizer(wx.horizontal) self.message="" self.write = wx.textctrl(panel, -1, style=wx.te_multiline, value=self.message) button_send = wx.button(panel, 1, label='b1') vbox.add(self.write, 1, wx.expand | wx.top | wx.right | wx.left | wx.bottom, 15) vbox.add(button_send, 0, wx.align_center | wx.top | wx.bottom, 20) self.bind(wx.evt_button, self.onsend, id=1) panel.setsizer(vbox) self.centre() def onsend(self, event): b=event.geteventobject().getlabel() if b.endswith('1'): self.message = self.message+"sss" self.write.setvalue(self.message) class myapp(wx.app): def oninit(self): frame = tom(none, -1, 'tom') frame.showmodal() frame.destroy() return true app = myapp() app.mainloop()
Comments
Post a Comment