我正在尝试按下按钮,更改面板上的文字,但是来自不同的功能。
例如:
status=wx.StaticText(panel,label="Yes",pos=(95,5),size=(50,20))
change=wx.Button(panel,label="Change",pos=(115,45),size=(50,20))
self.Bind(wx.EVT_BUTTON, self.changed, change)
def changed(self,event):
have it change the label to "no".
由于
答案 0 :(得分:2)
使用self.status.SetLabel
:
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title = title, size = (200, -1))
self.state = 'Yes'
self.panel = wx.Panel(self)
self.status = wx.StaticText(self.panel, label = self.state,
pos = (95, 5), size = (50, 20))
self.button = wx.Button(self.panel, label = 'Change',
pos = (115, 45), size = (50, 20))
self.Bind(wx.EVT_BUTTON, self.changed, self.button)
def changed(self, event):
self.state = 'Yes' if self.state == 'No' else 'No'
self.status.SetLabel(self.state)
app = wx.App(False)
frame = MyFrame(None, "Hello")
frame.Show()
app.MainLoop()