简单登陆窗口

  项目名称:编写一个登陆界面

  项目要求:

    1.输入用户名和密码

    2.登陆成功后显示欢迎界面

             3.输错三次后账户锁定

 

 项目需求分析:

  首先要有一个登陆界面,这里需要建立一个GUI的窗口用于输入用户名和密码,登陆界面中包括登陆界面的说明,用户名和密码的输入窗口,登陆按钮。输入正确还需要一个登陆成功的那个欢迎信息,输入错误有输入错误提示,三次失败之后需要提示账户已经锁定。即使重新打开界面账户依然锁定。

程序流程图:

项目代码:

 1 #encoding=utf-8
 2 __author__ = 'heng'
 3 '''
 4 ---------------------------------------------------------------------------
 5                             项目:编写一个登陆界面
 6                             项目需求:
 7                             1.输入用户名和密码
 8                             2.登陆成功后显示欢迎界面
 9                             3.输错三次后账户锁定
10 ----------------------------------------------------------------------------
11 '''
12 import wx
13 #用户的信息
14 user = 'xiaoli'
15 password = 'fucking'
16 #添加log按键的处理
17 def logDeal(event):
18     if user == userText.GetValue()and password == passText.GetValue():
19         the_succeedGUI()
20     else:
21         the_lowGUI()
22 
23 #登陆界面
24 def the_logGUI():
25     logApp = wx.App()
26     log_win = wx.Frame(None,title = '---------------please log--------------',size = (500,400))
27     bkg1 = wx.Panel(log_win)
28     userBUTTON = wx.Button(bkg1,label = 'user')
29     passwordBUTTON = wx.Button(bkg1,label = 'password')
30     logBUTTON = wx.Button(bkg1,label = 'log')    #登陆按钮
31     logBUTTON.Bind(wx.EVT_BUTTON,logDeal)
32     global userText
33     userText = wx.TextCtrl(bkg1)  #建立用户名的输入框
34     global passText
35     passText = wx.TextCtrl(bkg1)      #建立密码的输入框
36     #开始布局
37     box1 = wx.BoxSizer()     #添加尺寸器,默认水平布局
38     box1.Add(userBUTTON,flag = wx.LEFT | wx.Height,border = 5)
39     box1.Add(userText,flag = wx.LEFT,border = 5)
40     box2 = wx.BoxSizer()       #开始上下布局
41     box2.Add(box1,flag = wx.ALL,border = 5)
42     box2.Add(passwordBUTTON,flag = wx.LEFT,border = 5)
43     box2.Add(passText,flag = wx.LEFT|wx.Height,border = 5)
44     box3 = wx.BoxSizer(wx.VERTICAL)
45     box3.Add(box2,flag = wx.ALL,border = 5)
46     box3.Add(logBUTTON,flag = wx.LEFT,border = 200)
47     bkg1.SetSizer(box3)
48     log_win.Show()
49     logApp.MainLoop()
50 
51 #登陆成功的GUI
52 def the_succeedGUI():
53 
54     succeedApp = wx.App()
55     win2 = wx.Frame(None,title = 'you are succeed',size = (300,200))
56     the_succeed = wx.Button(win2,label = 'you are logging in  !  ')
57     win2.Show()
58     succeedApp.MainLoop()
59 
60 #登陆失败的GUI
61 def the_lowGUI():
62     lowApp = wx.App()
63     win3 = wx.Frame(None,title = "you arn't log in ",size = (300,200))
64     the_low = wx.Button(win3,label = "input fail! you have three chance")
65     win3.Show()
66     lowApp.MainLoop()
67 
68 #账户锁定GUI
69 def the_lockGUI():
70     lockApp = wx.App()
71     win4 = wx.Frame(None,title = 'the user have been lock!',size = (300,200))
72     the_lock = wx.Button(win4,label = "the user have been lock!")
73     win4.Show()
74     lockApp.MainLoop()
75 
76 the_logGUI()

代码还很不够完善。

未完待续。。。。

 

posted @ 2015-04-26 12:47  xiaoli2018  阅读(431)  评论(0编辑  收藏  举报