-4

(to make the error show you have to press the sign up button)Bare in mind I consider myself to be at a beginner level of coding. I'm doing a project for a for a controlled assessment in school and its for an imaginary guild and I have to create an interface that has a login/register system, an invoice system and an order system. These variables were global variables before and I was trying to figure out how to run the same code without having to make them global. I was told that use parameters and this "TypeError: FSSignup() missing 3 required positional arguments: 'eUsername', 'ePassword', and 'signupPage'" showed up. here's my code:

from tkinter import *
import os

details = 'tempfile.temp'  # sets variable details as tempfile


def signup():  # signup subroutine

    signupPage = Tk()  # makes empty signup window
    signupPage.geometry("450x400")  # sets size of window 500 pixels by 300
    signupPage.title("Signup for The Guild of Ceramic Arts")  # adds a title to the window

    introL = Label(signupPage, text="Please enter your details: ", font=("Arial", 15))  # heading
    introL.place(x=105, y=10)

    userL = Label(signupPage, text="New Username: ", font=("Arial", 14))  # user's detail's labels
    pwL = Label(signupPage, text="New Password: ", font=("Arial", 14))
    userL.place(x=20, y=50)
    pwL.place(x=20, y=80)

    eUsername = Entry(signupPage, font=("Arial", 14))  # user's detail's entries
    ePassword = Entry(signupPage, font=("Arial", 14), show='*')

    eUsername.place(x=170, y=50)  # Places entries for details
    ePassword.place(x=170, y=80)


    # adds signup button and command runs the subroutine named 'FSSignup' short for file save sign up
    signupB = Button(signupPage, text="Signup", font=("Arial", 12), command=FSSignup)
    signupB.place(x=180, y=360)

    mainloop()


def FSSignup(eUsername,  ePassword, signupPage):
    with open(details, 'w') as f:
        f.write(eUsername.get())
        f.write('\n')
        f.write(ePassword.get())
        f.write('\n')
        f.write(eForename.get())
        f.write('\n')
        f.write(eSurname.get())
        f.write('\n')
        f.write(eEmail.get())
        f.write('\n')
        f.write(ePhoneNum.get())
        f.write('\n')
        f.write(eAddress.get())
        f.write('\n')
        f.write(eCity_Town.get())
        f.write('\n')
        f.write(eCounty.get())
        f.close()

    signupPage.destroy()
    login()


def login():
    loginPage = Tk()
    loginPage.geometry("400x200")
    loginPage.title("Login for the Guild of Ceramic Arts")

    headingL = Label(loginPage, text="Please login: ", font=("Arial", 15))
    headingL.place(x=140, y=20)

    userL = Label(loginPage, text="Username: ", font=("Arial", 14))
    passwordL = Label(loginPage, text="Password: ", font=("Arial", 14))
    userL.place(x=20, y=50)
    passwordL.place(x=20, y=80)

    eUser = Entry(loginPage, font=("Arial", 14))
    epw = Entry(loginPage, font=("Arial", 14), show='*')
    eUser.place(x=120, y=50)
    epw.place(x=120, y=80)

    loginB = Button(loginPage, text='Login', font=("Arial", 12), command=checkLogin)
    loginB.place(x=130, y=120)

    delUserB = Button(loginPage, text='Delete User', fg='red', command=delUser, font=("Arial", 12))
    delUserB.place(x=190, y=120)

    mainloop()


def checkLogin(eUser, epw):
    with open(details) as f:
        data = f.readlines()
        uname = data[0].rstrip()
        pword = data[1].rstrip()

    if eUser.get() == uname and epw.get() == pword:
        return mainMenu()
    else:
        r = Tk()
        r.title('error')
        r.geometry('150x50')
        rlbl = Label(r, text='\n Invalid Login')
        rlbl.pack()
        r.mainloop()


def delUser(loginPage):
    os.remove(details)  # Removes the file
    loginPage.destroy()  # Destroys the login window
    signup()  # And goes back to the start


def mainMenu():
    pass



signup()
  • Have you tried creating a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example)? – finefoot Feb 18 '20 at 19:27
  • 1
    You've posted way too much code to be appropriate for stackoverflow. Please try to reduce this down to a [mcve]. If you have a problem with 10 global variables, you can illustrate the same problem with just one global variable. – Bryan Oakley Feb 18 '20 at 19:27
  • 1
    Read [Why are multiple instances of Tk discouraged?](https://stackoverflow.com/questions/48045401/why-are-multiple-instances-of-tk-discouraged) and [Tkinter understanding mainloop](https://stackoverflow.com/questions/29158220/tkinter-understanding-mainloop) – stovfl Feb 18 '20 at 19:41
  • 1
    ***""TypeError: FSSignup() missing 3 required positional arguments:"***: You have defined: `def FSSignup(eUsername, ePassword, signupPage):`, but you call: `command=FSSignup`. Where, did you think the arguments are comming from? – stovfl Feb 18 '20 at 19:45
  • 1
    1st problem is you have more than one instance of tk. You should update frames or new toplevel windows instead of creating multiple tk instances. 2nd problem is you build everything in functions. Because you do this you have no choice but to use globals or passing variables from one function to another. The best option is to build this using Classes as with OOP you can avoid global's with class attributes. The next best thing is to build your tk instance in the global namespace to begin with and work from there passing variables between functions. – Mike - SMT Feb 18 '20 at 19:45

1 Answers1

1

Put your code in main function. This way you can avoid using any global variables.

zailbreak
  • 19
  • 2