python - wxPython 按钮更改面板上的文本

标签 python wxpython

我正在尝试按下按钮来更改面板上的文本,但来自不同的功能。

例如:

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".

谢谢

最佳答案

使用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()

关于python - wxPython 按钮更改面板上的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9038238/

相关文章:

python - Hadoop:HiveServer2 的 Python 客户端驱动程序无法安装

python - 盒装OpenCV 3.4.2 VideoCapture字母

python - 从 csv 文件行中的日期切片

python - 使用WX显示文件路径

python - 更改 GUI 库 : QT, wxPython...还有什么?

python - 动态设置wx.GridBagSizer的大小

Python从文件中提取数据

python - 类型错误: 'float' 对象无法解释为整数

python - mysqldb更新报错typeerror 'str' object is not callable

python-2.7 - Python WX 从父框架调用子框架