Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
3.5 kB
3
Indexable
Never
import tkinter as tk
from tkinter.font import BOLD
class App(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.title('ATMBankingv0.1')
        self.geometry("720x720+0+0")
        
        self.resizable(False,False)
        self.app_data = {"name": tk.StringVar(), "pin": tk.StringVar()}
        container = tk.Frame(self)
        container.pack(side = "top", fill = "both", expand = True)
        container.grid_rowconfigure(0, weight = 1)
        container.grid_columnconfigure(0, weight = 1)

        self.frames = {}

        for F in (LoginPage, MainPage):
            page_name = F.__name__                
            frame = F(parent = container, controller = self)
            self.frames[page_name] = frame
            frame.grid(row=0, column = 0, sticky = "nsew")

        self.show_frame("LoginPage")

    def show_frame(self, page_name):
        frame = self.frames[page_name]
        frame.tkraise()



class LoginPage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        login_form = tk.Frame(self,width = 720, height = 640, bg = '#004d4d')
        login_form.pack(fill = "both", expand = True)
        please_text = tk.Label(login_form, text = "Please enter your login details", bg = "#004d4d", fg = "#b37700", font = ('Verdana', 12, BOLD))
        please_text.pack(pady = (80,10))
        fullname_label = tk.Label(login_form, text = "Full Name:", bg = "#004d4d", fg = "#b37700", font = ('Verdana', 15, BOLD))
        fullname_label.pack(pady = (100,5))
        self.name_entry = tk.Entry(login_form, textvariable = controller.app_data["name"], width = 20, font = ('Verdana', 12, BOLD), bd = 1)
        self.name_entry.pack()
        print(self.controller.app_data['name'].get())
        pin_label = tk.Label(login_form, text = "PIN:", bg = "#004d4d", fg = "#b37700", font = ('Verdana', 15 , BOLD))
        pin_label.pack(pady = (40,5))
        pin_entry = tk.Entry(login_form, width = 20, font = ('Verdana', 12, BOLD), bd = 1)
        pin_entry.pack()
        button_login = tk.Button(login_form, cursor = 'hand2', text = "LOGIN", width = 10, height = 3, font = ('Helvetica', 12, BOLD), command = lambda:controller.show_frame('MainPage'),bg = "#004d4d", fg = '#b37700')
        button_login.pack(pady = (40,5))
        bottom_frame = tk.Frame(self, width = 720, height = 30, bg = "#004d4d")
        bottom_frame.pack(fill = 'both')
        bottom_text = tk.Label(bottom_frame, text = "ATMBanking v0.1", bg = "#004d4d", fg = "#a6a6a6", font = ('Verdana', 6, BOLD))
        bottom_text.pack( side = tk.RIGHT)


class MainPage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self,parent)           
        self.controller = controller
        frame_text = tk.Frame(self, width = 720, height = 360, bg = "red")
        frame_text.pack(fill = 'x', pady = 200)
        name = self.controller.app_data['name'].get()
        lable1 = tk.Label(frame_text, text = f'Hello {name}')
        lable1.pack()
        button1 = tk.Button(frame_text, text = "click", command = lambda:self.asign_name())
        button1.pack()
    def asign_name(self):
        name = self.controller.app_data['name'].get()
        print(name)
        return name

if __name__ == "__main__":
    app = App()
    app.mainloop()