0

I have been currently stuck on an issue for weeks in regards to tkinter user entries. I have built out an application that contains multiple files.

File 1: RegisterPage.py

File 2: LoginPage.py

File 3: AccountPage.py

File 4: PersonalPage.py

File 5: Database.py (Psuedo database. Using path and os.listdir() for user file entries. Creates a .txt file that has the user's entries(firstname,lastname, contact, email, password) that were provided during RegisterPage.py.

LoginPage.py

from tkinter import Frame, Label, Entry, Button, messagebox
import tkinter as tk

MEDIUM_FONT = ("Times New Roman", 15, "bold")


class Login(tk.Frame):
    def __init__(self, master):
        tk.Frame.__init__(self, master)
        self.root = master
        self.root.geometry("1250x700+0+0")
        frame2 = Frame(self.root, bg='white')
        frame2.place(x=480, y=100, width=700, height=500)
        Label(frame2, text="EMAIL ADDRESS", font=MEDIUM_FONT, bg='white', fg='gray').place(x=50, y=150)
        self.email = Entry(frame2, font=MEDIUM_FONT, bg='lightgray')
        self.email.place(x=50, y=180, width=200)
        Label(frame2, text="Password", font=MEDIUM_FONT, bg='white', fg='gray').place(x=50, y=250)
        self.txt_password = Entry(frame2, font=MEDIUM_FONT, bg='lightgray', show='*')
        self.txt_password.place(x=50, y=280, width=200)
        Button(frame2, text="Sign In", bd=0, cursor='hand2',
           command=lambda: self.master.switch_frame("PersonalPage")).place(x=250, y=430, width=180)

    def login(self):
        fields = [self.email.get(),
              self.txt_password.get()]
        for entries in fields:
            if entries == "":
                 messagebox.showerror("Error", "All Fields Are Required", parent=self.root)
                 return
            if self.database.login_check(self.email.get(), self.txt_password.get()):
                 messagebox.showinfo("Success", "Logged In", parent=self.root)
                 self.master.switch_frame("AccountPage")
                 return
            messagebox.showinfo("Error", "Email or Password Does Not Match", parent=self.root)
            return

PersonalPage.py

from tkinter import Frame, Label
import tkinter as tk


MEDIUM_FONT = ("Times New Roman", 15, "bold")


class PersonalDetails(tk.Frame):
    def __init__(self, master):
        tk.Frame.__init__(self, master)
        self.root = master
        self.root.title("Personal Details")
        self.root.geometry("1250x700+0+0")
        self.root.config(bg='white')
        frame3 = Frame(self.root, bg='white')
        frame3.place(x=480, y=100, width=700, height=500)

        Label(frame3, text="Email", font=MEDIUM_FONT, bg='white', fg='gray').place(x=50, y=350)
        Label(frame3, textvariable='', font=MEDIUM_FONT)

Controller.py. (python3 Controller.py) to run program

import tkinter as tk
from LoginPage import Login
from PersonalPage import PersonalDetails

pages = {
"LoginPage": Login,
"PersonalPage": PersonalDetails
}


class Controller(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self._frame = None
        self.switch_frame("LoginPage")

    def switch_frame(self, page_name):
        cls = pages[page_name]
        new_frame = cls(master=self)
        if self._frame is not None:
            self._frame.destroy()
        self._frame = new_frame
        self._frame.place()


if __name__ == '__main__':
    app = Controller()
    app.mainloop()

How would I be able to display the LOGGED IN User's personal details in PersonaPage.py after User successfully matched the email and password lines located in his distinct .txt file in the "Accounts Directory"? I am not sure how to bridge that connection between LoginPage.py and PersonalPage.py. Do I need to provide a unique identifier in LoginPage.py?

AccountPage.py is more of a "middle-man-frame" ,with a button that switches the frame to PersonalPage.py, between LoginPage.py and PersonalPage.py.

TimMTech93
  • 9
  • 1
  • 4
  • I am currently using an OOP approach as well. – TimMTech93 Dec 07 '21 at 22:56
  • It's no different in tkinter than in any other python program. You need to be given or need to be able to get a reference to the object you want to interact with. Please [edit] your question to include a [mcve]. Even though you mention four files in your question, you should be able to create a program that only uses two. – Bryan Oakley Dec 07 '21 at 23:04
  • I will edit the question in a more minimal repro way in a bit. When you mean only two, do you mean one file for the frames and the other for the functions? – TimMTech93 Dec 07 '21 at 23:09
  • This is also a Banking System that will be implementing a “Deposit” and “Withdraw” frames that will perform the business logic(currency transfer). – TimMTech93 Dec 07 '21 at 23:10
  • You said the problem is between LoginPage.py and PersonalPage.py, so we only need reduced versions of those files, and just enough code to tie them together. – Bryan Oakley Dec 07 '21 at 23:19
  • I have updated the original post. I added the Database and Controller due to them being essential in the process on how the files are being read and how the frames are being switched. – TimMTech93 Dec 07 '21 at 23:36
  • We don't need the database. Your question is about passing an entry widget from one frame to another, so we only need two frames. Please try to reduce the amount of code in your post. You can probably remove half of it. – Bryan Oakley Dec 08 '21 at 00:18
  • Understood. I removed the database and the controller. I removed the controller since you are originator of the switch_frames method. – TimMTech93 Dec 08 '21 at 00:22
  • We need to be able to run the code in your question. Please make sure your example, is _minimal_ while still being runnable and while still reproducing your problem. Please read the article at the following line: [mcve]. – Bryan Oakley Dec 08 '21 at 00:59
  • I have minimized the code as much as possible to reproduce a working program. – TimMTech93 Dec 08 '21 at 02:35
  • Why don't you use instance variables in `Controller` class to share across frames? – acw1668 Dec 08 '21 at 02:40
  • Does this solve your problem? https://stackoverflow.com/questions/33646605/how-to-access-variables-from-different-classes-in-tkinter. Or this? https://stackoverflow.com/questions/32212408/how-to-get-variable-data-from-a-class? Or this? https://stackoverflow.com/questions/48731097/calling-functions-from-a-tkinter-frame-to-another – Bryan Oakley Dec 08 '21 at 03:31
  • I will have a look. Hopefully it answers my questions since my application is connected with a directory handling multiple user’s credentials and this application is not meant for only one user to register/log in. I’m going to have to implement it that way some how. – TimMTech93 Dec 08 '21 at 04:14
  • Hello Bryan. The links only solved my problem partially. The transition from LoginPage.py and PersonalPage.py only holds the email entry, which displays in my PersonalPage.py without an issue. However, my PersonalPage.py contains firstname, lastname and contact as well. Since my LoginPage.py does not provide an entry for those, how can I display firstname, lastname and contact on my PersonalPage.py? – TimMTech93 Dec 08 '21 at 21:56
  • Actually, it made my problem even worse. I am convinced that these methods are not reliable for security applications such as a Bank. But thank you for all of your help. – TimMTech93 Dec 09 '21 at 00:21

0 Answers0