impa导入包使用说明

功能:

command_run(c:str=...) -> None:
make_error(error=''):
class Str:

├─move_str_list(content):

class tkinter:

├─ScrolledText_CodeBox(self,txtContent):"""ScrolledText转换为代码框"""

class PromptBox:

├─_init_(self):"""运行辅助"""

├─close_(self):"""运行辅助"""

├─help_ConfirmBox_(self):"""运行辅助"""

├─help_ChoiceBox_1(self):"""运行辅助"""

├─help_ChoiceBox_2(self):"""运行辅助"""

├─while_(self,content,name,button_text,color):"""运行辅助"""

├─while_2(self,content,name,button_text1,button_text2,color):"""运行辅助"""

├─ConfirmBox(self,content='欢迎使用WSL的产品《PromptBox》, 感谢您的支持'
│             ,name='提示',button_text='确认'
│             ,button_command=None,color='black'):"""确认框"""

├─ChoiceBox(self,content='欢迎使用WSL的产品《PromptBox》, 感谢您的支持'
│          ,name='选择',button_text1='确认'
│          ,button_text2='取消',button_command1=None
│          ,button_command2=None,color='black'):"""选择框"""

├─LoginBox(self,new=True):"""登录界面"""

所需导入包:

tkinter

threading

idlelib

pickle

这是代码分支文件:

#<PromptBox_LoginBox.py>
# -*- coding: utf-8 -*-
"""
Created on Sun Aug  5 10:34:10 2018
@author: Administrator
"""
import tkinter as tk
import tkinter.messagebox
import pickle
#窗口
run=True
window=tk.Tk()
window.title('登录')
window.geometry('450x300')
#画布放置图片
canvas=tk.Canvas(window,height=300,width=500)
#imagefile=tk.PhotoImage(file='截图20220815170728.png')
#image=canvas.create_image(0,0,anchor='nw',image=imagefile)
#canvas.pack(side='top')
#标签 用户名密码
tk.Label(window,text='用户名:').place(x=100,y=150)
tk.Label(window,text='密码:').place(x=100,y=190)
#用户名输入框
var_usr_name=tk.StringVar()
entry_usr_name=tk.Entry(window,textvariable=var_usr_name)
entry_usr_name.place(x=160,y=150)
#密码输入框
var_usr_pwd=tk.StringVar()
entry_usr_pwd=tk.Entry(window,textvariable=var_usr_pwd,show='*')
entry_usr_pwd.place(x=160,y=190)
name=None
a_name=None
a_pwd=None
aaaaaa=True
#登录函数
def usr_log_in():
    global name,a_name,a_pwd
    #输入框获取用户名密码
    usr_name=var_usr_name.get()
    a_name=var_usr_name.get()
    usr_pwd=var_usr_pwd.get()
    a_pwd=var_usr_pwd.get()
    #从本地字典获取用户信息,如果没有则新建本地数据库
    try:
        with open('usr_info.pickle','rb') as usr_file:
            usrs_info=pickle.load(usr_file)
    except FileNotFoundError:
        with open('usr_info.pickle','wb') as usr_file:
            usrs_info={'admin':'admin'}
            pickle.dump(usrs_info,usr_file)
    #判断用户名和密码是否匹配
    if usr_name in usrs_info:
        if usr_pwd == usrs_info[usr_name]:
            name=usr_name
            tk.messagebox.showinfo(title='welcome',
                                   message='欢迎您:'+usr_name)
            window.destroy()
        else:
            tk.messagebox.showerror(message='密码错误')
    #用户名密码不能为空
    elif usr_name=='' or usr_pwd=='' :
        tk.messagebox.showerror(message='用户名或密码为空')
    #不在数据库中弹出是否注册的框
    else:
        is_signup=tk.messagebox.askyesno('欢迎','您还没有注册,是否现在注册')
        if is_signup:
            usr_sign_up()
#注册函数
def usr_sign_up():
    global a_name,a_pwd,aaaaaa
    #确认注册时的相应函数
    def signtowcg():
        import tkinter
        #获取输入框内的内容
        nn=new_name.get()
        np=new_pwd.get()
        npf=new_pwd_confirm.get()
  
        #本地加载已有用户信息,如果没有则已有用户信息为空
        try:
            with open('usr_info.pickle','rb') as usr_file:
                exist_usr_info=pickle.load(usr_file)
        except FileNotFoundError:
            exist_usr_info={}           
             
        #检查用户名存在、密码为空、密码前后不一致
        if nn in exist_usr_info:
            tk.messagebox.showerror('错误','用户名已存在')
        elif np =='' or nn=='':
            tk.messagebox.showerror('错误','用户名或密码为空')
        elif np !=npf:
            tk.messagebox.showerror('错误','密码前后不一致')
        #注册信息没有问题则将用户名密码写入数据库
        else:
            exist_usr_info[nn]=np
            with open('usr_info.pickle','wb') as usr_file:
                pickle.dump(exist_usr_info,usr_file)
            tk.messagebox.showinfo('欢迎','注册成功')
            #注册成功关闭注册框
            window_sign_up.destroy()
    #新建注册界面
    window_sign_up=tk.Toplevel(window)
    window_sign_up.geometry('350x200')
    window_sign_up.title('注册')
    #用户名变量及标签、输入框
    #print(a_name)
    if a_name!=None:
        new_name=tk.StringVar(value=a_name)#name=a_name)
    else:
        new_name=tk.StringVar()
    help(new_name)
    tk.Label(window_sign_up,text='用户名:').place(x=10,y=10)
    tk.Entry(window_sign_up,textvariable=new_name).place(x=150,y=10)
    #if a_name!=None:
    #    new_name.insert(tkinter.END, a_name)
    #    new_name.see(tkinter.END)
    #    new_name.update()
    #密码变量及标签、输入框
    if a_pwd!=None:
        new_pwd=tk.StringVar(value=a_pwd)
    else:
        new_pwd=tk.StringVar()
    tk.Label(window_sign_up,text='请输入密码:').place(x=10,y=50)
    tk.Entry(window_sign_up,textvariable=new_pwd,show='*').place(x=150,y=50)
    #if a_pwd!=None:
    #    new_pwd.insert(tkinter.END, a_pwd)
    #    new_pwd.see(tkinter.END)
    #    new_pwd.update()
    #重复密码变量及标签、输入框
    if a_pwd!=None:
        new_pwd_confirm=tk.StringVar(value=a_pwd)
    else:
        new_pwd_confirm=tk.StringVar()
    tk.Label(window_sign_up,text='请再次输入密码:').place(x=10,y=90)
    tk.Entry(window_sign_up,textvariable=new_pwd_confirm,show='*').place(x=150,y=90)
    #if a_pwd!=None:
    #    new_pwd_confirm.insert(tkinter.END, a_pwd)
    #    new_pwd_confirm.see(tkinter.END)
    #    new_pwd_confirm.update()
    #确认注册按钮及位置
    bt_confirm_sign_up=tk.Button(window_sign_up,text='确认注册',
                                 command=signtowcg)
    bt_confirm_sign_up.place(x=150,y=130)
#global window_sign_up
#退出的函数
def usr_sign_quit():
    global window_sign_up
    window.destroy()
    #window_sign_up.destroy()
    #exit()
#登录 注册按钮
bt_login=tk.Button(window,text='登录',command=usr_log_in)
bt_login.place(x=140,y=230)
bt_logup=tk.Button(window,text='注册',command=usr_sign_up)
bt_logup.place(x=210,y=230)
bt_logquit=tk.Button(window,text='退出',command=usr_sign_quit)
bt_logquit.place(x=280,y=230)
#主循环
window.mainloop()
run=False
#print(name)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值