《python程序设计基础(第3版)》第9章 GUI课后习题

1.设计一个窗口,并放置一个按钮,单机按钮后弹出颜色对话框,关闭颜色对话框后提示选中的颜色。

import wx
class COLOR(wx.Frame):
    def __init__(self, superion):
        wx.Frame.__init__(self, parent=superion, title='COLOR', size=(400,200))
        panel = wx.Panel(self)
        self.buttonOK = wx.Button(parent=panel, label='OK', pos=(70,90))
        self.Bind(wx.EVT_BUTTON, self.OnButtonCheck, self.buttonOK)

    def OnButtonCheck(self, event):
        colorDlg=wx.ColourDialog(None)
        colorDlg.ShowModal()
        color=colorDlg.GetColourData().Colour
        wx.MessageBox(str(color))
  
if __name__ == '__main__':
    app = wx.App()
    frame = COLOR(None)
    frame.Show()
    app.MainLoop()

  

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

 

3.设计一个窗体,模拟QQ登录界面,当用户输入号码123456和密码654321时提示正确,否则提示错误

 

import wx
class QQ(wx.Frame):
    def __init__(self, superion):
        wx.Frame.__init__(self, parent=superion, title='QQ', size=(250,150),pos=(350,350))
        panel = wx.Panel(self)
        panel.SetBackgroundColour('Red')
        label1=wx.StaticText(panel,-1,'账号:',pos=(0,10),style=wx.ALIGN_CENTER)
        label1=wx.StaticText(panel,-1,'密码:',pos=(0,30),style=wx.ALIGN_CENTER)
        self.username=wx.TextCtrl(panel,-1,pos=(70,10),size=(160,20))
        self.password=wx.TextCtrl(panel,pos=(70,30),size=(160,20),style=wx.TE_PASSWORD)
        self.buttonOK = wx.Button(parent=panel, label='登录', pos=(70,60))
        self.Bind(wx.EVT_BUTTON, self.OnButtonCheck, self.buttonOK)
        self.buttonRes = wx.Button(parent=panel, label='注册', pos=(70,90))
        self.Bind(wx.EVT_BUTTON, self.OnButtonRes, self.buttonRes)

    def OnButtonCheck(self, event):
        user=self.username.GetValue()
        psw=self.password.GetValue()
        if user == '123456' and psw == '654321':
            wx.MessageBox('成功!')
        else:
            wx.MessageBox('你输入的账号或密码有误!')
    def OnButtonRes(self,event):
        wx.MessageBox("嘿嘿告诉你个秘密---账号:123456 密码:654321")
        
if __name__ == '__main__':
    app = wx.App()
    frame = QQ(None)
    frame.Show()
    app.MainLoop()

  • 3
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值