zoukankan      html  css  js  c++  java
  • python登陆窗口实例

    # Author:979
    # blog addr:http://www.cnblogs.com/home979/
    #引用自:https://www.cnblogs.com/wwf828/p/7418181.html
    
    import tkinter as tk
    from tkinter import messagebox
    import pickle
    
    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)
    
    def usr_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)
        except FileNotFoundError:
            with open('usrs_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]:
                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?')
            if is_sign_up:
                usr_sign_up()
    
    def usr_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()
  • 相关阅读:
    自我介绍篇
    iOS支付宝集成时遇到的问题整理(2)
    iOS支付宝集成时遇到的问题整理(1)
    注册登录时本地图片验证码
    集成ZBar时容易遇到的问题以及解决方法
    iOS解析数据时Error=3840
    iOS开发中的一些定时器
    二维码扫描利用ZBar实现
    去除UITableView中多余的分割线或者隐藏cell间的分割线
    iOS 中二维码扫描
  • 原文地址:https://www.cnblogs.com/home979/p/8535630.html
Copyright © 2011-2022 走看看