Python私人网址记事本(tkinter)

相较于之前的记事本: 

Python制作私人网站记事本_Windy.Zhhh的博客-CSDN博客

做了一些改进,如今的在tkinter窗口上运行,初始密码设置为空,各位可根据第六行代码修改初始密码。

import tkinter as tk
import os

def main():
    def e1_get():
        if e1.get()=='':
            def write():
                name=en1.get()
                url=en2.get()
                f=open('store.txt','r')
                line=f.readline()
                if line=='':
                    file_txt=open('store.txt',mode='a')
                    data={}
                    data[name]=url
                    file_txt.write(str(data)[0:-1]+','+'}')
                    file_txt.close()
                    en1.delete(0,'end')
                    en2.delete(0,'end')
                else:
                    with open("store.txt", 'rb+') as filehandle:
                        filehandle.seek(-1, os.SEEK_END)
                        filehandle.truncate()
                    file_txt = open('store.txt', mode='a')
                    data = {}
                    data[name] = url
                    file_txt.write(str(data)[1:-1] + "," + "}")
                    file_txt.close()
                    en1.delete(0, 'end')
                    en2.delete(0, 'end')

            def en3_get():
                te1.delete("1.0", "end")
                key=en3.get()
                file_txt = open('store.txt', mode='r')
                line = file_txt.readline()
                value=eval(line).get(key)
                file_txt.close()
                te1.insert('end',value)

            def word():
                print('')
                f=open('store.txt','r').readline()
                f=f[1:-2]
                for i in f:
                    if i=="'":
                        pass
                    elif i==',':
                        print('')
                    else:
                        print(i,end='')

            window.destroy()
            root=tk.Tk()
            root.title('Write')
            root.geometry('400x450+550+300')
            l1=tk.Label(root,text='网站名:',font=('方正舒体',23),width=6,height=2)
            l1.grid(row=0,column=0)
            en1 = tk.Entry(root,font=('Consolas',15))
            en1.grid(row=0,column=1)
            l2=tk.Label(root,text='网址:',font=('方正舒体',23),width=6,height=2)
            l2.grid(row=1,column=0)
            en2 = tk.Entry(root,font=('Consolas',15))
            en2.grid(row=1,column=1)
            bt1 = tk.Button(root, text='确认写入', font=('华文新魏', 20), width=8, command=write)
            bt1.grid(row=2, column=1)
            l3=tk.Label(root,text='查询:',font=('方正舒体',23),width=6,height=2)
            l3.grid(row=3,column=0)
            en3=tk.Entry(root,font=('Consolas',15))
            en3.grid(row=3,column=1)
            bt2=tk.Button(root,font=('华文新魏',20), width=8,text='确认查询', command=en3_get)
            bt2.grid(row=4,column=1)
            te1=tk.Text(root,width=40,height=1)
            te1.grid(row=5,column=1)
            bt3=tk.Button(root,font=('华文新魏',20),width=10,text='打印储存库', command=word)
            bt3.grid(row=6,column=1)
            root.mainloop()
        else:
            pass
    window=tk.Tk()
    window.title('MyNote')
    window.geometry("400x150+550+300")
    lan=tk.Label(window,text='用户登录',font=('方正舒体',23),width='100',height='2').pack()
    window.resizable(width=False, height=False)
    e1=tk.Entry(window,show='*',font=15)
    e1.pack()
    b1=tk.Button(window,text='确认',command=e1_get,font=('华文新魏', 15),width=7, height=1)
    b1.pack()
    window.mainloop()



if __name__ == '__main__':
    main()

你可能感兴趣的:(Python,python,开发语言)