使用remi自己编写的一个简单判断记录的网站登录界面,需要配置两个文件,Config/Web.txt和,Config/WebUserPasswd.txt。
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2021/2/24 15:40
# @Author : singweek
# @File : Web.py
import remi.gui as gui
from remi import start, App
import os
import time
import threading
class MyApp(App):
def __init__(self, *args):
super(MyApp, self).__init__(*args)
def main(self):
self.WebConfigDict=self.Get_WebConfig()
self.Login_page()#登录界面
self.Main_page()#主界面
self.Register_page()#注册界面
return self.LoginMenu#返回主登录界面
def Register_page(self):
#register page
self.RegisterMenu = gui.Container(width=480, height=400, layout_orientation=gui.Container.LAYOUT_VERTICAL,
style={'margin': '0px auto', 'background': 'gray'})
self.RegisterLabel = gui.Label(self.WebConfigDict["RegisterLabel"], width='80%', height='100px',
style={'margin': '60px 50px 10px', 'padding-top': '30px', 'font-size': '30px',
'font-weight': 'bold', 'color': 'Blue', 'line-height': '40px',
'text-align': 'center'})
UserMenu = gui.Container(width='80%', height='60px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL,
style={'margin': '0px auto', 'background': 'gray'})
RegisterUserLabel = gui.Label('账 号:', width='20%', height='35px',
style={'margin': '10px 10px 10px', 'padding-top': '5px', 'font-size': '20px',
'line-height': '10px', 'text-align': 'center'})
self.RegisterUserText = gui.TextInput(width='70%', height='20px',
style={'margin': '0px auto', 'padding-top': '20px', 'padding-left': '5px',
'font-size': '20px', 'line-height': '5px', 'text-align': 'left',
'border': '1px solid white', 'background': 'white'})
UserMenu.append([RegisterUserLabel, self.RegisterUserText])
PasswdMenu = gui.Container(width='80%', height='60px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL,
style={'margin': '0px auto', 'background': 'gray'})
RegisterPasswdLabel = gui.Label('密 码:', width='20%', height='35px',
style={'margin': '10px 10px 10px', 'padding-top': '5px', 'font-size': '20px',
'line-height': '10px', 'text-align': 'center'})
self.RegisterPasswdText = gui.TextInput(width='70%', height='20px',
style={'margin': '0px auto', 'padding-top': '20px', 'padding-left': '5px',
'font-size': '20px', 'line-height': '5px', 'text-align': 'left',
'border': '1px solid white', 'background': 'white'})
PasswdMenu.append([RegisterPasswdLabel, self.RegisterPasswdText])
PhoneMenu = gui.Container(width='80%', height='60px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL,
style={'margin': '0px auto', 'background': 'gray'})
PhoneLabel = gui.Label('手机:', width='20%', height='35px',
style={'margin': '10px 10px 10px', 'padding-top': '5px', 'font-size': '20px',
'line-height': '10px', 'text-align': 'center'})
self.PhoneText = gui.TextInput(width='70%', height='20px',
style={'margin': '0px auto', 'padding-top': '20px', 'padding-left': '5px',
'font-size': '20px', 'line-height': '5px', 'text-align': 'left',
'border': '1px solid white', 'background': 'white'})
PhoneMenu.append([PhoneLabel, self.PhoneText])
BtnMenu = gui.Container(width='70%', height='40px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL,
style={'margin': '0px auto', 'background': 'gray'})
self.RegisterBtn = gui.Button('注册', width='60px', height='30px',
style={'margin': '20px 80px 20px', 'font-size': '20px', 'line-height': '5px',
'text-align': 'center'})
BackBtn = gui.Button('返回', width='60px', height='30px',
style={'margin': '20px 0px 20px', 'font-size': '20px', 'line-height': '5px',
'text-align': 'center'})
BtnMenu.append([self.RegisterBtn,BackBtn])
self.RegisterMenu.append([self.RegisterLabel, UserMenu, PasswdMenu, PhoneMenu, BtnMenu])
self.RegisterBtn.onclick.connect(self.register_menu)
BackBtn.onclick.connect(self.login_page)
def Login_page(self):
# Login page
self.LoginMenu = gui.Container(width=480, height=400, layout_orientation=gui.Container.LAYOUT_VERTICAL,
style={'margin': '0px auto', 'background': 'gray'})
LoginLabel = gui.Label(self.WebConfigDict["LoginTitle"], width='80%', height='100px',
style={'margin': '60px 50px 10px', 'padding-top': '30px', 'font-size': '30px',
'font-weight': 'bold', 'color': 'Blue', 'line-height': '40px',
'text-align': 'center'})
UserMenu = gui.Container(width='80%', height='100px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL,
style={'margin': '0px auto', 'background': 'gray'})
LoginUserLabel = gui.Label('账 号:', width='20%', height='35px',
style={'margin': '10px 10px 10px', 'padding-top': '5px', 'font-size': '20px',
'line-height': '10px', 'text-align': 'center'})
self.LoginUserText = gui.TextInput(width='70%', height='20px',
style={'margin': '0px auto', 'padding-top': '20px', 'padding-left': '5px',
'font-size': '20px', 'line-height': '5px', 'text-align': 'left',
'border': '1px solid white', 'background': 'white'})
UserMenu.append([LoginUserLabel, self.LoginUserText])
PasswdMenu = gui.Container(width='80%', height='100px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL,
style={'margin': '0px auto', 'background': 'gray'})
LoginPasswdLabel = gui.Label('密 码:', width='20%', height='35px',
style={'margin': '10px 10px 10px', 'padding-top': '5px', 'font-size': '20px',
'line-height': '10px', 'text-align': 'center'})
self.LoginPasswdText = gui.TextInput(width='70%', height='20px',
style={'margin': '0px auto', 'padding-top': '20px',
'padding-left': '5px',
'font-size': '20px', 'line-height': '5px', 'text-align': 'left',
'border': '1px solid white', 'background': 'white'})
PasswdMenu.append([LoginPasswdLabel, self.LoginPasswdText])
BtnMenu = gui.Container(width='100%', height='40px', layout_orientation=gui.Container.LAYOUT_HORIZONTAL,
style={'margin': '0px auto', 'background': 'gray'})
LoginBtn = gui.Button('登录', width='20%', height='30px',
style={'margin': '10px 20% 10px', 'font-size': '20px', 'line-height': '5px',
'text-align': 'center'})
RegisterBtn = gui.Button('注册', width='20%', height='30px',
style={'margin': '10px 4% 10px', 'font-size': '20px', 'line-height': '5px',
'text-align': 'center'})
BtnMenu.append([LoginBtn, RegisterBtn])
self.LoginUserText.set_text("admin")
self.LoginPasswdText.set_text("admin")
self.LoginMenu.append([LoginLabel, UserMenu, PasswdMenu, BtnMenu])
LoginBtn.onclick.connect(self.login_menu)
RegisterBtn.onclick.connect(self.register_page)
def Main_page(self):
# Main container scoreboard page
self.MainMenu = gui.Container(width=1080, height=960, style={'margin': '20px auto', 'background': 'gray'})
LogoffBtn = gui.Button('注销', width='10%', height='20px',
style={'margin': '0px 90% 0px', 'padding-top': '0px','font-size': '20px', 'line-height': '5px',
'text-align': 'center'})
self.MainLable = gui.Label(self.WebConfigDict["MainLabel"], width='100%', height='35px',
style={'margin': '0px 0px 0px', 'padding-top': '0px', 'font-size': '40px',
'line-height': '35px', 'text-align': 'center','color':'red'})
self.MainMenu.append([LogoffBtn,self.MainLable,])
LogoffBtn.onclick.connect(self.logoff)
def register_page(self,emitter):
"""注册界面"""
self.set_root_widget(self.RegisterMenu)
self.RegisterBtn.onclick.connect(self.register_menu)
def login_page(self,emitter):
"""注册后手动返回登录界面"""
self.LoginUserText.set_text('')
self.LoginPasswdText.set_text('')
self.set_root_widget(self.LoginMenu)
def register_menu(self,emitter):
"""注册界面功能"""
user = self.RegisterUserText.get_text()
passwd = self.RegisterPasswdText.get_text()
phone=self.PhoneText.get_text()
if len(user)>=1 and len(passwd)>=6 and len(phone)==11:
self.Add_WebUserPasswd([user,passwd,phone])
for i in range(10,0,-1):
self.RegisterLabel.set_text("注册成功%s秒后返回登录界面"%i)
self.set_root_widget(self.RegisterMenu)
time.sleep(1)
self.set_root_widget(self.LoginMenu)
else:
self.RegisterLabel.set_text("注册账号密码手机号有误")
self.set_root_widget(self.RegisterMenu)
self.RegisterUserText.set_text('')
self.RegisterPasswdText.set_text('')
self.PhoneText.set_text('')
def login_menu(self, emitter):
"""登录界面判断跳转"""
userpasswddict=self.Get_WebUserPasswd()
user = self.LoginUserText.get_text()
passwd = self.LoginPasswdText.get_text()
if user in userpasswddict.keys():
if userpasswddict[user]==passwd:
self.set_root_widget(self.MainMenu)
else:
self.set_root_widget(self.LoginMenu)
self.LoginUserText.set_text("账号或密码错误请重新输入")
self.LoginPasswdText.set_text('')
else:
self.set_root_widget(self.LoginMenu)
self.LoginUserText.set_text("账号或密码错误请重新输入")
self.LoginPasswdText.set_text('')
def logoff(self, emitter):#返回主界面
"""注销发挥登录界面"""
self.LoginUserText.set_text('')
self.LoginPasswdText.set_text('')
self.set_root_widget(self.LoginMenu)
def Get_WebConfig(self,file="./Config/Web.txt"):
"""网页配置参数获取"""
datadict = {}
with open(file, 'r', encoding="utf-8") as f:
for i in f.readlines():
tmp = i[:-1].split("=")
if len(tmp) == 2:
datadict.update({tmp[0]: tmp[1]})
return datadict
def Get_WebUserPasswd(self,file="./Config/WebUserPasswd.txt"):
"""账号密码获取"""
datadict = {}
with open(file, 'r', encoding="utf-8") as f:
for i in f.readlines():
tmp = i[:-1].split("=")
if len(tmp) == 3:
datadict.update({tmp[0]: tmp[1]})
return datadict
def Add_WebUserPasswd(self,data, file="./Config/WebUserPasswd.txt"):
"""账号密码增加"""
with open(file, 'a+', encoding="utf-8") as f:
f.write(data[0] + '=' + data[1] +'=' + data[2]+ '\n')
if __name__ == "__main__":
start(MyApp, address='', port=8082, multiple_instance=False, enable_file_cache=True, update_interval=0.1,
start_browser=True)
配置文件内容:
Web.txt
LoginTitle=测试登录
RegisterLabel=测试注册
MainLabel=测试主界面
WebUserPasswd.txt
admin=admin=13100001111
其他功能,可以再此基础上,根据官网文档自己编写修改。