(要使错误显示出来,您必须按下注册按钮)请记住,我认为自己是初学者。我正在做一个项目,以便在学校进行受控评估,并为一个虚构的行会做准备,我必须创建一个具有登录/注册系统,发票系统和订单系统的界面。这些变量以前是全局变量,我试图弄清楚如何运行相同的代码而不必使其全局。有人告诉我使用参数,并且此“ TypeError:FSSignup()缺少3个必需的位置参数:'eUsername','ePassword'和'signupPage'”显示。 这是我的代码:
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()
答案 0 :(得分:1)
将您的代码放入main
函数中。这样,您可以避免使用任何全局变量。