如何在 wxpython 中控制 TextCtrl 的动态功能?
how to control a function of TextCtrl as dynamic in wxpython?
我是 wxpython 用户。我有一个关于如何控制 TextCtrl 功能的问题。我想要构建的程序是,如果您单击某个按钮,TextCtrl 的值将被更改。遵循我的源代码。
#!/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()
如果谁知道解决办法请给我留言。谢谢。
使用self.write.SetValue()
使用 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()
我是 wxpython 用户。我有一个关于如何控制 TextCtrl 功能的问题。我想要构建的程序是,如果您单击某个按钮,TextCtrl 的值将被更改。遵循我的源代码。
#!/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()
如果谁知道解决办法请给我留言。谢谢。
使用self.write.SetValue()
使用 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()