记录 python |
您所在的位置:网站首页 › Python窗口程序设置 › 记录 python |
利用tkinter里面的Entry,做的一个账户密码登陆。账户密码是里面设定的,如果加入数据库,应该从二维表中获取到用户名和密码,再做匹配判断。 在用Entry的过程中,注意利用user_name = tk.StringVar()这个语句,否则entry.get()获取不到里面输入的值,并且区分大小写。 应该是如果密码正确提醒密码正确,直接 import tkinter as tk import tkinter.messagebox def original_window(): enter_w = tk.Tk() enter_w.title('original_window') enter_w.geometry('750x500') lab_1 = tk.Label(enter_w,width=7,text='用户名',compound='center') lab_1.place(x=200,y=200) lab_2 = tk.Label(enter_w,width=7,text='密码',compound='center') lab_2.place(x=200,y=230) global uesr_name,password user_name = tk.StringVar() password= tk.StringVar() ###########获取登陆账号和密码########## entry = tk.Entry(enter_w,textvariable=user_name) #用户名 entry.pack() entry.place(x=310,y=200) entry_1 = tk.Entry(enter_w,show="*",textvariable=password) #show使密码不可见 entry_1.pack() entry_1.place(x=310,y=230) def panduan(enter_w): if entry.get() != 'test' or entry_1.get() !='123': tk.messagebox.showerror('*_*','密码错误,请重新输入') else: tk.messagebox.showinfo('^_^','密码正确,欢迎使用本软件') new_window(enter_w) btn = tk.Button(enter_w,text='登陆',fg="black",width=7,compound='center',\ bg = "white",command = lambda :panduan(enter_w)) btn.pack() btn.place(x=330,y=270) enter_w.mainloop() def new_window(enter_w): window_one = tk.Toplevel(enter_w) window_one.geometry('300x400') window_one.title('新界面') Lab = tk.Label(window_one,text='new window',compound = tk.CENTER) Lab.pack() original_window()效果图:
|
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |