Advertisement
Guest User

KBW

a guest
Jan 7th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.61 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import messagebox
  3.  
  4.  
  5. btnCRUDROW = 1
  6. ACCOUNTROW = 2
  7. PASSWORDROW = 3
  8. btnLOGINROW = 4
  9.  
  10. user_Info = {'admin':'pass01', 'manage':'pass02'}
  11.  
  12.  
  13. def open_main_window(old_page):
  14.     # btn pixel
  15.     X_PIXEL01 = 0
  16.     X_PIXEL02 = 80
  17.     X_PIXEL03 = 160
  18.     Y_PIXEL01 = 20
  19.     Y_PIXEL02 = 50
  20.     Y_PIXEL03 = 80
  21.     global G_user_name
  22.  
  23.     old_page.destroy()
  24.     win_main = tk.Tk()
  25.     win_main.title("main page")
  26.     win_main.geometry('300x200')
  27.     label_Lusername = tk.Label(win_main, text="User Name:").place(x=0,y=0)
  28.     label_username = tk.Label(win_main,text=G_user_name).place(x=80, y=0)
  29.     btn_open_page01 = tk.Button(win_main, text='products', command= lambda:open_page01_window(win_main)).place(x=X_PIXEL01,y=Y_PIXEL01)
  30.     btn_open_page02 = tk.Button(win_main, text='page02', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL02,y=Y_PIXEL01)
  31.     btn_open_page03 = tk.Button(win_main, text='page03', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL03,y=Y_PIXEL01)
  32.     btn_open_page04 = tk.Button(win_main, text='page04', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL01,y=Y_PIXEL02)
  33.     btn_open_page05 = tk.Button(win_main, text='page05', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL02,y=Y_PIXEL02)
  34.     btn_open_page06 = tk.Button(win_main, text='page06', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL03,y=Y_PIXEL02)
  35.     btn_open_page07 = tk.Button(win_main, text='page07', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL01,y=Y_PIXEL03)
  36.     btn_open_page08 = tk.Button(win_main, text='page08', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL02,y=Y_PIXEL03)
  37.     btn_open_page09 = tk.Button(win_main, text='page09', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL03,y=Y_PIXEL03)
  38.  
  39. def open_page01_window(old_page):
  40.     LABEL_YPIXEL = 20
  41.     NAME_XPIXEL = 0
  42.     STOCK_XPIXEL = 80
  43.     PRICE_XPIXEL = 160
  44.     PURCHASE_XPIXEL = 240
  45.     EFFECT_XPIXEL = 350
  46.     ORIGIN_XPIXEL = 430
  47.     RETURNS_XPIXEL = 500
  48.     old_page.destroy()
  49.     win_products = tk.Tk()
  50.     win_products.title("page01")
  51.     win_products.geometry('600x400')
  52.  
  53.     label_Lusername = tk.Label(win_products, text="User Name:").place(x=0, y=0)
  54.     label_username = tk.Label(win_products, text=G_user_name).place(x=80, y=0)
  55.     label_Lname = tk.Label(win_products, text="Name").place(x=NAME_XPIXEL, y=LABEL_YPIXEL)
  56.     label_Lstock = tk.Label(win_products, text="Stock").place(x=STOCK_XPIXEL, y=LABEL_YPIXEL)
  57.     label_Lprice = tk.Label(win_products, text="Price").place(x=PRICE_XPIXEL, y=LABEL_YPIXEL)
  58.     label_Lpurchase = tk.Label(win_products, text="Purchase").place(x=PURCHASE_XPIXEL, y=LABEL_YPIXEL)
  59.     label_Leffectivedate = tk.Label(win_products, text="Date").place(x=EFFECT_XPIXEL, y=LABEL_YPIXEL)
  60.     label_Lorigin = tk.Label(win_products, text="Origin").place(x=ORIGIN_XPIXEL, y=LABEL_YPIXEL)
  61.     label_Lreturns = tk.Label(win_products, text="Returns").place(x=RETURNS_XPIXEL, y=LABEL_YPIXEL)
  62.     btn_open_main = tk.Button(win_products, text='return', command=lambda:open_main_window(win_products)).pack(side="bottom")
  63.  
  64.  
  65. def usr_login():
  66.     global var_account
  67.     global var_password
  68.     global win_login
  69.     global G_user_name
  70.     usr_name = var_account.get()
  71.     usr_pwd = var_password.get()
  72.     if usr_name in user_Info:
  73.         if usr_pwd == user_Info[usr_name]:
  74.             G_user_name = usr_name
  75.             messagebox.showinfo(title='Welcome', message='How are you?' + usr_name)
  76.             open_main_window(win_login)
  77.         else:
  78.             messagebox.showerror(message='Error, your password is wrong, try again.')
  79.     else:
  80.         messagebox.askyesno('Welcome','You have not sign up yet. Sign up today?')
  81.  
  82. def login_frame():
  83.     global var_account
  84.     global var_password
  85.     global win_login
  86.     win_login = tk.Tk()
  87.     win_login.title("Log in")
  88.     var_account = tk.StringVar()
  89.     var_password = tk.StringVar()
  90.  
  91.     label=tk.Label(win_login, text="Log in!")
  92.     label_account=tk.Label(win_login, text="account")
  93.     label_password=tk.Label(win_login, text="password")
  94.     entry_account=tk.Entry(win_login, textvariable=var_account)
  95.     entry_password=tk.Entry(win_login, show='*', textvariable=var_password)
  96.     btn_login=tk.Button(win_login, text="Log in", command=usr_login)
  97.     label.grid(column=0,row=0)
  98.  
  99.  
  100.     label_account.grid(column=0,row =ACCOUNTROW)
  101.     entry_account.grid(column=1,row =ACCOUNTROW)
  102.     label_password.grid(column=0,row =PASSWORDROW)
  103.     entry_password.grid(column=1,row =PASSWORDROW)
  104.     btn_login.grid(row = btnLOGINROW)
  105.  
  106.     win_login.mainloop()
  107.  
  108. login_frame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement