制作登入保存打开功能的记录本

from tkinter import *
import tkinter as tk
import random
import time
import os


def mkdir(path):
    # 引入模块
    import os

    # 去除首位空格
    path = path.strip()
    # 去除尾部 \ 符号
    path = path.rstrip("\\")

    # 判断路径是否存在
    # 存在     True
    # 不存在   False
    isExists = os.path.exists(path)

    # 判断结果
    if not isExists:
        # 如果不存在则创建目录
        # 创建目录操作函数
        os.makedirs(path)

        print
        path + ' 创建成功'
        return True
    else:
        # 如果目录存在则不创建,并提示目录已存在
        print
        path + ' 目录已存在'
        return False


# 定义要创建的目录
mkpath = "d:\\qttc\\web\\"


# 调用函数

def translate():
    contnt =Entry(root, textvariable=re, width=40).get()
    contnt = contnt.strip()
    re.set(contnt)
    contnt1 = Entry(root, textvariable=re1, width=40).get()
    contnt1 = contnt1.strip()
    re1.set(contnt1)
    f = open('D:\\记录本\\user.txt', 'a+')
    f = open('D:\\记录本\\user.txt', "r")
    t = f.read()
    if t !="":
     di = t.split("\n")
     if di[0]==re.get() and di[1]==re1.get():
        #print("denruchengon")
        root.destroy()
        def sendMsg():  # 发送消息
            con = Entry(app, textvariable=rs, width=40).get()
            con = con.strip()
            rs.set(con)
            #print(txtMsg.get('0.0', END))
            if str(rs.get()) != '' and  txtMsg.get('0.0', END)!="":
                def moon():
                    cot = Entry(ap, textvariable=rsu, width=40).get()
                    cot = cot.strip()
                    rsu.set(cot)
                    if str(rsu.get()) != '':
                        f = open("D:\\记录本\\"+rsu.get()+".txt", 'a+')
                        f.write(rs.get())
                        f.write("\n")
                        f.write(txtMsg.get('0.0', END))
                        app.destroy()
                        ap.destroy()



                ap = Tk()
                ap.title('保存路径')
                screenwidth = ap.winfo_screenwidth()
                screenheight = ap.winfo_screenheight()
                # 设置界面宽度为530,高度为365像素,并且基于屏幕居中
                width = 420
                height = 70
                size = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
                ap.geometry(size)
                Label(ap, text="输入文件名:").grid(row=0, column=0, sticky='W', pady=5)
                rsu = StringVar()
                Entry(ap, textvariable=rsu, width=40).grid(row=0, column=1, sticky='W')
                btnSend = Button(ap, text='保存', width=8, command=moon)
                btnSend.grid(row=0, column=2)
                Label(ap, text="手动输入如有问题,请将文件名粘贴复制输入").grid(row=1, column=1, sticky='W', pady=5)


        def openMsg():
            def dakai():
                #global txtMsg
                conx = Entry(a, textvariable=rsx, width=40).get()
                conx = conx.strip()
                rsx.set(conx)
                if str(rsx.get())!="":
                    try:
                        fo = open("D:\\记录本\\" + rsx.get() + ".txt","r", encoding='UTF-8')
                        m=0
                        for line in fo.readlines():
                            if m==0:
                                rs.set(line)
                            else:
                                txtMsg.insert(END,line)
                            m=m+1
                        a.destroy()
                    except:

                        def cancel():
                            p.destroy()

                        p = Tk()
                        p.title('错误!!!')
                        screenwidth = p.winfo_screenwidth()
                        screenheight = p.winfo_screenheight()
                        # 设置界面宽度为530,高度为365像素,并且基于屏幕居中
                        width = 160
                        height = 90
                        size = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
                        p.geometry(size)
                        Label(p, text="文件不存在,请重新输入。").grid(row=0, column=0, sticky='W', pady=5)
                        btnss = Button(p, text='关闭', width=8, command=cancel)
                        btnss.grid(row=1, column=0)




            a = Tk()
            a.title('打开路径')
            screenwidth = a.winfo_screenwidth()
            screenheight = a.winfo_screenheight()
            # 设置界面宽度为530,高度为365像素,并且基于屏幕居中
            width = 420
            height = 90
            size = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
            a.geometry(size)
            Label(a, text="输入路径:").grid(row=1, column=0, sticky='W', pady=5)
            rsx = StringVar()
            Entry(a, textvariable=rsx, width=40).grid(row=1, column=1, sticky='W')
            btnSend = Button(a, text='保存', width=8, command=dakai)
            btnSend.grid(row=1, column=2)
            Label(a, text="手动输入如有问题,请将文件名粘贴复制输入").grid(row=0, column=1, sticky='W')
            Label(a, text="---打开后尽量别更改,会出现文件内容重复---").grid(row=2, column=1, sticky='W')



        def cancelMsg():
              txtMsg.delete('0.0', END)

        def sendMsgEvent(event):  # 发送消息事件
            if event.keysym == 'Up':
                sendMsg()

        # 创建窗口
        app = Tk()
        app.title('记录本')
        Label(app, text="文本标题:").grid(row=0, column=0, sticky='W', pady=0)
        rs = StringVar()
        Entry(app, textvariable=rs, width=40).grid(row=0, column=1, sticky='W')
        mooi = '当前时间为:' + time.strftime("%Y-%m-%d ", time.localtime())
        Label(app, text=mooi).grid(row=1, column=1, sticky='W', pady=0)

        # 创建frame容器
        #frmLT = Frame(width=600, height=100, bg='white')
        frmLC = Frame(width=500, height=330, bg='white')
        frmLB = Frame(width=540, height=50)
        frmRT = Frame(width=5, height=400)

        # 创建控件
        #txtMsgList = Text(frmLC)
        #txtMsgList.tag_config('greencolor', foreground='#008C00')  # 创建tag
        txtMsg = Text(frmLC)
        txtMsg.bind("<KeyPress-Up>", sendMsgEvent)
        btnSend = Button(frmLB, text='保存', width=8, command=sendMsg,padx=10)
        btnCancel = Button(frmLB, text='删除(全部)', width=8, command=cancelMsg)
        btnopen = Button(frmLB, text='打开文件', width=8, command=openMsg)


        # 窗口布局
        #frmLT.grid(row=0, column=0, columnspan=2, padx=1, pady=3)
        frmLC.grid(row=2, column=0, columnspan=2, padx=1, pady=3)
        frmLB.grid(row=3, column=0, columnspan=2)
        frmRT.grid(row=0, column=2, rowspan=3, padx=2, pady=3)

        # 固定大小
        #frmLT.grid_propagate(0)
        frmLC.grid_propagate(0)
        frmLB.grid_propagate(0)
        frmRT.grid_propagate(0)

        btnSend.grid(row=3, column=0)
        btnCancel.grid(row=3, column=1)
        btnopen.grid(row=3, column=2)
        #txtMsgList.grid()
        txtMsg.grid()



def zhuche():
    f = open('D:\\记录本\\user.txt', 'a+')
    f = open('D:\\记录本\\user.txt')
    t = f.read()
    #print(t)
    if t == "":
      def zhuch():
        global x
        x= random.randint(1000, 9999)
        label = Label(self, text=str(x))
        label.grid(row=6, column=1)

      def zhu():
        global x
        content = Entry(self, textvariable=res, width=40).get()
        content = content.strip()
        res.set(content)
        content1 = Entry(self, textvariable=res1, width=40).get()
        content1 = content1.strip()
        res1.set(content1)
        content2 = Entry(self, textvariable=res2, width=40).get()
        content2 = content2.strip()
        res2.set(content2)
        m=res.get()
        n=res1.get()
        #print(m)
        #print(x)
        if eval(res2.get())==x and str(res.get()) != '' and str(res1.get())!='':
                f=open('D:\\记录本\\user.txt','a+')
                f.write(m)
                f.write("\n")
                f.write(n)
                f.write("\n")
                self.destroy()
      x=0
      self = Tk()
      self.title('注册页面')
      screenwidth = self.winfo_screenwidth()
      screenheight = self.winfo_screenheight()
      # 设置界面宽度为530,高度为365像素,并且基于屏幕居中
      width = 450
      height = 300
      size = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
      self.geometry(size)
      label = Label(self, text="--请完善个人信息并记住账号,密码--")
      label.grid(row=0, column=1)
      label = Label(self, text="--欢迎你的使用--")
      label.grid(row=1, column=1)
      Label(self, text="输入账号:").grid(row=2, column=0, sticky='W', pady=5)
      res = StringVar()
      Entry(self, textvariable=res, width=40).grid(row=2, column=1, sticky='W')
      Label(self, text="输入密码:").grid(row=3, column=0, sticky='W', pady=5)
      res1 = StringVar()
      Entry(self, textvariable=res1, width=40).grid(row=3, column=1, sticky='W')
      Label(self, text="输入验证码:").grid(row=4, column=0, sticky='W', pady=5)
      res2= StringVar()
      Entry(self, textvariable=res2, width=40).grid(row=4, column=1, sticky='W')
      button = Button(self, text='获取验证码', width='10', command=zhuch)
      button.grid(row=4, column=2, sticky=E, pady=10)
      button = Button(self, text='注册', width='10', command=zhu)
      button.grid(row=5, column=1, sticky=E, pady=10)

mkdir("D:\\记录本")
root=Tk()
root.title('记录本登入入口')
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
# 设置界面宽度为530,高度为365像素,并且基于屏幕居中
width =  450
height = 300
size = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
root.geometry(size)
Label(root, text="").grid(row=0, pady=5, columnspan=3)
label=Label(root,text="---欢迎你的使用---")
label.grid(row=0,column=1,padx=15)
label=Label(root,text="请完善个人信息并记住账号,密码")
label.grid(row=1,column=1)
Label(root, text="输入账号:").grid(row=2, column=0, sticky='W', pady=5)
re = StringVar()
Entry(root, textvariable=re, width=40).grid(row=2, column=1, sticky='W')
Label(root, text="输入密码:").grid(row=3, column=0, sticky='W', pady=5)
re1 = StringVar()
Entry(root, textvariable=re1, width=40).grid(row=3, column=1, sticky='W')
button=Button(root,text='注册',width='10',command=zhuche)
button.grid(row=4,column=0,sticky = E,pady=10)
button=Button(root,text='登入',width='10',command=translate)
button.grid(row=4,column=1,sticky = E,pady=10)
label=Label(root,text="注意:如果按键无反应,是因为信息输入不全或错误")
label.grid(row=5,column=1)
label=Label(root,text="---希望你能对软件满意---")
label.grid(row=6,column=1)
root.mainloop()

尽力用已知知识制作了一个小型软件,代码重复率较高。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值