python制作登陆窗口_python登陆窗口实例

#Author:979#blog addr:http://www.cnblogs.com/home979/#引用自:https://www.cnblogs.com/wwf828/p/7418181.html

importtkinter as tkfrom tkinter importmessageboximportpickle

window=tk.Tk()

window.title('Welcome to Mofan Python')

window.geometry('500x300')#welcome image

canvas = tk.Canvas(window, height=200, width=500)

image_file= tk.PhotoImage(file='logo.png')

image= canvas.create_image(0,0, anchor='nw', image=image_file)

canvas.pack(side='top')#user information

tk.Label(window, text='用户名:').place(x=50, y= 150)

tk.Label(window, text='密码:').place(x=50, y= 190)#tk.Label(window, text='百度地图密匙: ').place(x=50, y= 220)

#建立输入框

var_usr_name =tk.StringVar()

var_usr_name.set('home979@outlook.com')

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)defusr_login():

usr_name=var_usr_name.get()

usr_pwd=var_usr_pwd.get()try:

with open('usrs_info.pickle', 'rb') as usr_file:

usrs_info=pickle.load(usr_file)exceptFileNotFoundError:

with open('usrs_info.pickle', 'wb') as usr_file:

usrs_info= {'admin': 'admin'}

pickle.dump(usrs_info, usr_file)if usr_name inusrs_info:if usr_pwd ==usrs_info[usr_name]:

tk.messagebox.showinfo(title='Welcome', message='How are you?' +usr_name)else:

tk.messagebox.showerror(message='Error, your password is wrong, try again.')else:

is_sign_up= tk.messagebox.askyesno('Welcome','You have not sign up yet. Sign up today?')ifis_sign_up:

usr_sign_up()defusr_sign_up():

exit()return

#login and sign up button

btn_login = tk.Button(window, text='Login', command=usr_login)

btn_login.place(x=170, y=230)

btn_sign_up= tk.Button(window, text='Sign up', command=usr_sign_up)

btn_sign_up.place(x=270, y=230)

window.mainloop()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值