使用easygui简单图形化界面库模拟用户登录和注册-董老师(peter)

import easygui

#声明变量username和password存储原来的账号与密码

username='nnmm'

password='20071119'

#账号注册(输入账号,可以为新账号,也可以是已注册账号)

username1=easygui.enterbox('请输入您的账号:')

#声明变量bool1与bool2并赋值为True和False

bool1=True

bool2=False

#当bool1为True时,执行while循环语句,否则跳出while循环

while bool1:

    if username1!=username:

        easygui.msgbox('您的账号还未注册!')

    #ccbox()方法用于两种情况的选择

        result=easygui.ccbox('这里是注册页面','是否同意注册',('是','否'))

        if result==True:

            easygui.msgbox('欢迎来到注册页面')

            username1=easygui.enterbox('请输入您所要注册的账号:')

            username=username1

            #输入验证码验证

            code=easygui.enterbox('请输入手机验证码:')

            password1=easygui.enterbox('请设置新密码:')

            password=password1

            easygui.msgbox('注册成功,请直接登录!')

            username1=easygui.enterbox('请输入已注册账号:')

            bool=True

    #当bool或者bool2为True时,请输入密码

    while bool or bool2:

        password1=easygui.enterbox('请输入密码:')

        if username1==username and password1==password:

            easygui.msgbox('欢迎来到购物系统,祝您购物愉快!')

            bool=False

            bool1=False

            bool2=False

        else:

            easygui.msgbox('您的账号或密码输入错误!')

            username1=easygui.enterbox('请输入已注册的账号:')

        if bool==False and bool1==False and bool2==False:                     

            equipment=easygui.choicebox('选择你要的装备','装备购买',('冷静之靴','极寒风暴','暗影战斧','无尽之刃','名刀司命'))

            price=int(easygui.enterbox('请输入产品单价:'))

            num=int(easygui.enterbox('请输入你购买的数量:'))

            sum=price*num

            #逻辑判断,买卖规则

            money='本次购物需要'+str(sum)+'金币'

            if equipment=='冷静之靴':

                easygui.msgbox(money)

            elif equipment=='极寒风暴':

                easygui.msgbox(money)

            elif equipment=='暗影战斧':

                easygui.msgbox(money)

            elif equipment=='无尽战刃':    

                easygui.msgbox(money)

            elif equipment=='名刀司命':

                easygui.msgbox(money)

            else:

                easygui.msgbox('您输入的商品不存在!')

    if username1 == username and password1 == password:

        bool2 = True

            

猜你喜欢

转载自www.cnblogs.com/dongks/p/11831838.html