• 大小: 5KB
    文件类型: .py
    金币: 2
    下载: 1 次
    发布日期: 2021-06-11
  • 语言: Python
  • 标签: UI  python  

资源简介

python 编写用户登录界面 1.输入用户名密码 2.认证成功后显示欢迎信息 3.输错三次后锁定

资源截图

代码片段和文件信息

# -*- coding: utf-8 -*-
# -*- coding: cp936 -*-

import getpass
import Tkinter as tk
import time
import datetime
import tkMessageBox


“““
1.输入用户名密码
2.认证成功后显示欢迎信息
3.输错三次后锁定

“““

count = 0

def tick():
    global time1
    # 从运行程序的计算机上面获取当前的系统时间
    time2 = time.strftime(‘%Y-%m-%d %H:%M:%S‘)
    # 如果时间发生变化,代码自动更新显示的系统时间
    if time2 != time1:
        time1 = time2
        clock.config(text=time2)
        # calls itself every 200 milliseconds
        # to update the time display as needed
        # could use >200 ms but display gets jerky
    clock.after(200 tick)
    
def handler():
    
    ‘‘‘事件处理函数‘‘‘
    global count
    global t1 t2
    username = entry.get()
    password = entry2.get()
  
    if count > 3:
        t2 = time.strftime(‘%Y-%m-%d %H:%M:%S‘ time.localtime())
        t2= datetime.datetime.strptime(t2‘%Y-%m-%d %H:%M:%S‘)
        dateline = datetime.timedelta( seconds=12  minutes=0 hours=0)
        if (dateline - (t2 - t1)).days == 0:
            print (u‘密码输入错误超过3次,该账号已被锁定,请‘)
            print dateline - (t2 - t1)
            print (u‘小时之后再试‘ )
            var = ‘密码输入错误超过3次,该账号已被锁定,请‘ + str(dateline - (t2 - t1))  + ‘小时之后再试‘
            tkMessageBox.showwarning(‘警告‘ var )
        if (dateline - (t2 - t1)).days < 0:
            count  = 0
            print (u‘账号锁定已解除,请输入正确的账号密码!‘)
            tkMessageBox.showwarning(‘警告‘‘账号锁定已解除,请输入正确的账号密码!‘)
            
    else:
        if username == ‘‘ and password == ‘‘:
            tkMessageBox.showinfo(‘警告‘‘账号和密码不能为空‘)
        elif username == ‘‘ and password != ‘‘:
            tkMessageBox.showinfo(‘警告‘‘账号不能为空‘)
        elif username != ‘‘ and password == ‘‘:
            tkMessageBox.showinfo(‘警告‘‘密码不能为空‘)   
        else:       
            if  username == ‘Navy‘ and password == ‘9527‘:
                print(u‘欢迎 Navy‘)
                window.destroy()
                tkMessageBox.showinfo(‘主页面‘‘欢迎 Navy‘)

            else:

评论

共有 条评论