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