首页 > 试题广场 >

设计一个窗体,并放置一个按钮,按钮默认文本为“开始”,单击按

[问答题]

设计一个窗体,并放置一个按钮,按钮默认文本为“开始”,单击按钮后文本变为“结束”,再次单击后变为“开始”,循环切换。

Python 2.7.8代码如下,

import wx
class wxGUI(wx.App):
    def OnInit(self):
        frame = wx.Frame(parent=None, title='wxGUI', size=(160,140))
        panel = wx.Panel(frame, -1)        
        
        self.buttonOK = wx.Button(panel, -1, 'Start', pos=(0,0))
        self.Bind(wx.EVT_BUTTON, self.OnButtonOK, self.buttonOK)
        
        frame.Show()
        return True
    def OnButtonOK(self, event):
        text = self.buttonOK.GetLabelText()
        if text == 'Start':
            self.buttonOK.SetLabelText('End')
        elif text == 'End':
            self.buttonOK.SetLabelText('Start')
    
app = wxGUI()
app.MainLoop()

发表于 2017-12-28 15:57:38 回复(1)