Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import messagebox
- btnCRUDROW = 1
- ACCOUNTROW = 2
- PASSWORDROW = 3
- btnLOGINROW = 4
- user_Info = {'admin':'pass01', 'manage':'pass02'}
- def open_main_window(old_page):
- # btn pixel
- X_PIXEL01 = 0
- X_PIXEL02 = 80
- X_PIXEL03 = 160
- Y_PIXEL01 = 20
- Y_PIXEL02 = 50
- Y_PIXEL03 = 80
- global G_user_name
- old_page.destroy()
- win_main = tk.Tk()
- win_main.title("main page")
- win_main.geometry('300x200')
- label_Lusername = tk.Label(win_main, text="User Name:").place(x=0,y=0)
- label_username = tk.Label(win_main,text=G_user_name).place(x=80, y=0)
- btn_open_page01 = tk.Button(win_main, text='products', command= lambda:open_page01_window(win_main)).place(x=X_PIXEL01,y=Y_PIXEL01)
- btn_open_page02 = tk.Button(win_main, text='page02', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL02,y=Y_PIXEL01)
- btn_open_page03 = tk.Button(win_main, text='page03', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL03,y=Y_PIXEL01)
- btn_open_page04 = tk.Button(win_main, text='page04', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL01,y=Y_PIXEL02)
- btn_open_page05 = tk.Button(win_main, text='page05', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL02,y=Y_PIXEL02)
- btn_open_page06 = tk.Button(win_main, text='page06', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL03,y=Y_PIXEL02)
- btn_open_page07 = tk.Button(win_main, text='page07', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL01,y=Y_PIXEL03)
- btn_open_page08 = tk.Button(win_main, text='page08', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL02,y=Y_PIXEL03)
- btn_open_page09 = tk.Button(win_main, text='page09', command=lambda: open_page01_window(win_main)).place(x=X_PIXEL03,y=Y_PIXEL03)
- def open_page01_window(old_page):
- LABEL_YPIXEL = 20
- NAME_XPIXEL = 0
- STOCK_XPIXEL = 80
- PRICE_XPIXEL = 160
- PURCHASE_XPIXEL = 240
- EFFECT_XPIXEL = 350
- ORIGIN_XPIXEL = 430
- RETURNS_XPIXEL = 500
- old_page.destroy()
- win_products = tk.Tk()
- win_products.title("page01")
- win_products.geometry('600x400')
- label_Lusername = tk.Label(win_products, text="User Name:").place(x=0, y=0)
- label_username = tk.Label(win_products, text=G_user_name).place(x=80, y=0)
- label_Lname = tk.Label(win_products, text="Name").place(x=NAME_XPIXEL, y=LABEL_YPIXEL)
- label_Lstock = tk.Label(win_products, text="Stock").place(x=STOCK_XPIXEL, y=LABEL_YPIXEL)
- label_Lprice = tk.Label(win_products, text="Price").place(x=PRICE_XPIXEL, y=LABEL_YPIXEL)
- label_Lpurchase = tk.Label(win_products, text="Purchase").place(x=PURCHASE_XPIXEL, y=LABEL_YPIXEL)
- label_Leffectivedate = tk.Label(win_products, text="Date").place(x=EFFECT_XPIXEL, y=LABEL_YPIXEL)
- label_Lorigin = tk.Label(win_products, text="Origin").place(x=ORIGIN_XPIXEL, y=LABEL_YPIXEL)
- label_Lreturns = tk.Label(win_products, text="Returns").place(x=RETURNS_XPIXEL, y=LABEL_YPIXEL)
- btn_open_main = tk.Button(win_products, text='return', command=lambda:open_main_window(win_products)).pack(side="bottom")
- def usr_login():
- global var_account
- global var_password
- global win_login
- global G_user_name
- usr_name = var_account.get()
- usr_pwd = var_password.get()
- if usr_name in user_Info:
- if usr_pwd == user_Info[usr_name]:
- G_user_name = usr_name
- messagebox.showinfo(title='Welcome', message='How are you?' + usr_name)
- open_main_window(win_login)
- else:
- messagebox.showerror(message='Error, your password is wrong, try again.')
- else:
- messagebox.askyesno('Welcome','You have not sign up yet. Sign up today?')
- def login_frame():
- global var_account
- global var_password
- global win_login
- win_login = tk.Tk()
- win_login.title("Log in")
- var_account = tk.StringVar()
- var_password = tk.StringVar()
- label=tk.Label(win_login, text="Log in!")
- label_account=tk.Label(win_login, text="account")
- label_password=tk.Label(win_login, text="password")
- entry_account=tk.Entry(win_login, textvariable=var_account)
- entry_password=tk.Entry(win_login, show='*', textvariable=var_password)
- btn_login=tk.Button(win_login, text="Log in", command=usr_login)
- label.grid(column=0,row=0)
- label_account.grid(column=0,row =ACCOUNTROW)
- entry_account.grid(column=1,row =ACCOUNTROW)
- label_password.grid(column=0,row =PASSWORDROW)
- entry_password.grid(column=1,row =PASSWORDROW)
- btn_login.grid(row = btnLOGINROW)
- win_login.mainloop()
- login_frame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement