首页 > 试题广场 >

2 [问答]设计一个窗体,并放置一个按钮,按钮默认文本为“开

[问答题]
设计一个窗体,并放置一个按钮,按钮默认文本为“开始”,单击按钮后文本变为“结束”,再次单击后变为“开始”,循环切换。
import wx
class MyFrame(wx.Frame):
    def __init__(self, superion):
        wx.Frame.__init__(self, parent=superion, title='开始--结束', size=(400,200))
        panel = wx.Panel(self)
        self.buttonOK = wx.Button(parent=panel, label='开始', pos=(70,90))
        self.Bind(wx.EVT_BUTTON, self.OnButtonCheck, self.buttonOK)
 
    def OnButtonCheck(self, event):
        string=self.buttonOK.GetLabelText()
        if string == '开始':
            self.buttonOK.SetLabelText('结束')
        elif string == '结束':
            self.buttonOK.SetLabelText('开始')
  
if __name__ == '__main__':
    app = wx.App()
    frame = MyFrame(None)
    frame.Show()
    app.MainLoop()

发表于 2019-07-20 17:35:43 回复(0)