我已经按照本教程介绍如何进行GUI注册和登录系统:https://www.youtube.com/watch?v=Xt6SqWuMSA8
一切都很完美,但就我而言,该程序不会像用户视频中那样使用用户名和密码创建文件。
就我而言,它只会生成一个空白的.txt文件。
您可以在每分钟18:45观看我在视频中的意思。
这是我按下“ Inregistrare”后的外观:
它应该再创建一个名为。asds.txt
的.txt文件。
我遵循了他的教程,并且可以正常工作,但该文件包含用户名和密码的事实除外。我不知道还能尝试什么,所以我决定问你。
import time
from tkinter import *
import sys
def inregistrare_utilizator():
usernameInfo = utilizator.get()
passwordInfo = parola.get()
file = open(usernameInfo + ".txt", "w")
file.write(usernameInfo + "\n")
file.write(passwordInfo)
file.close()
utilizatorEntry.delete(0, END)
parolaEntry.delete(0, END)
labe1 = Label(windows4, text="succes").pack()
def register():
global windows4
windows4 = Tk()
windows4.title("EasyQuizy v1.0 - Inregistrare")
windows4.geometry("400x200+180+350")
windows4.resizable(False, False)
label1 = Label(windows4, text="Completeaza campurile de mai jos pentru inregistrare.")
label1.pack()
label2 = Label(windows4, text="Tot ce este notat cu * este obligatoriu!")
label2.pack()
label5 = Label(windows4, text="")
label5.pack()
label3 = Label(windows4, text="Username* ")
label3.place(x=60, y=80)
label4 = Label(windows4, text="Parola* ")
label4.place(x=60, y=110)
inregistrareButon = Button(windows4, text="Inregistrare", command=inregistrare_utilizator)
inregistrareButon.pack()
inregistrareButon.place(x=180, y=150)
global utilizator
global parola
global utilizatorEntry
global parolaEntry
utilizator = StringVar()
parola = StringVar()
utilizatorEntry = Entry(windows4, textvariable=utilizator, width=20)
utilizatorEntry.pack()
utilizatorEntry.place(x=150, y=80)
parolaEntry = Entry(windows4, textvariable=parola, width=20)
parolaEntry.pack()
parolaEntry.place(x=150, y=110)
windows4.mainloop()
def succes():
global windows2
windows2 = Tk()
windows2.overrideredirect(1)
windows2.geometry("300x50+760+450")
windows2.title("EasyQuizy v1.0")
windows2.resizable(False, False)
windows2.after(2000, lambda: windows2.destroy())
text = Label(windows2, width=300, height=25, text="Succes!", borderwidth=4, relief=RIDGE, fg="#4bf04b",
bg="#F9F8F9", font="arial 22 bold underline", command=windows1.destroy()).pack(anchor=CENTER)
text2 = Label(windows2, command=inceput())
text2.pack()
windows2.mainloop()
def drepturi_autor():
global frame
frame = Frame(windows3, highlightbackground="black", highlightcolor="black", highlightthickness=2, width=(390),
height=(150), bg="#afd5c1")
frame.place(x=105, y=90)
label1 = Label(frame, width=(26),
text="EasyQuizy este o aplicatieee e\ncreata de mine pentru tine.\nTest test test teste test\nTest test test teste test\nTest test test teste test",
bg="#82ac96", fg="#f2f2f2", font="arial 14 bold italic")
label1.pack(side=LEFT)
label1.place(x=7, y=5)
frame.after(2000, frame.destroy)
def inceput():
global windows3
windows3 = Tk()
windows3.title("EasyQuizy v1.0")
windows3.geometry("600x600+600+200")
windows3.resizable(False, False)
windows3.configure(bg="#472025")
headerFrame = Frame(windows3, width=("100"), height=("0")).pack(side=TOP)
frameLeft = Frame(windows3, width="100", height="600", bg="#7b8781")
frameLeft.place(x=0, y=0)
frameRight = Frame(windows3, width="100", height="600", bg="#7b8781")
frameRight.place(x=500, y=0)
header = Label(headerFrame, width=("100"), height=("3"), bg="#9d7448", fg="#d9ab33", borderwidth=1, relief="solid",
font="Helvetica 14 bold italic", text=("Bine ai venit, " + str(numeUtilizator.get()) + '!'))
header.pack()
# BUTOANE PE PARTEA STANGA!
butonRights = Button(frameLeft, width=("9"), height=("2"), text="Drepturi de \nautor", bg="#6ab891", fg="#131313",
font="arial 8 bold", borderwidth=4, relief="raised", command=drepturi_autor)
butonRights.place(x=7, y=100)
############################################################
butonInfo = Button(frameLeft, width=("9"), height=("2"), text="Imbunatatiri", bg="#6ab891", fg="#131313",
font="arial 8 bold", borderwidth=4, relief="raised")
butonInfo.place(x=7, y=180)
butonExit = Button(frameRight, width=6, height=2, text="Exit", bg="#c51418", fg="#131313",
font="arial 10 bold underline", borderwidth=4, relief=RAISED, command=sys.exit)
butonExit.place(x=15, y=540)
#############################################################477998
butonRegister = Button(headerFrame, width=10, height=2, bg="#477998", fg="#291f1e", text="Inregistrare",
font="arial 8 bold", borderwidth=4, relief="raised", command=register)
butonRegister.place(x=28, y=15)
############################################################
butonLogin = Button(headerFrame, width=11, bg="#c4d6b0", fg="#291f1e", height=2, text="Autentificare",
font="arial 8 bold", borderwidth=4, relief="raised")
butonLogin.place(x=480, y=15)
windows3.mainloop()
global windows1
windows1 = Tk()
windows1.title("EasyQuizy v1.0")
windows1.geometry("1280x720+300+160")
windows1.resizable(False, False)
header = Label(windows1, text="Bun venit la EasyQuizy, un joc de inteligenţă şi strategie!", bg="#878067",
fg="#A1BBCD", font=("arial 16 bold"), width=("200"), height=("3"))
header.pack()
# Introducere nume
numePreluareText = Label(windows1, text="Numele tău: ", font="arial 12", fg="black")
numePreluareText.pack(anchor=CENTER)
doar_12_caractere = Label(windows1, width="24", text="ATENŢIE! Maxim 12 caractere!", font="arial 10 italic",
fg="red", bg="#b6b0b0")
doar_12_caractere.place(x=517, y=200)
global numeUtilizator
numeUtilizator = StringVar()
EntryNume = Entry(windows1, textvariable=numeUtilizator, font="arial 12", bg="#c8c6bd")
EntryNume.pack(anchor=CENTER)
# FUNCTIE!!!!
def length(numeUtilizator):
if len(numeUtilizator.get()) > 12:
numeUtilizator.set(numeUtilizator.get()[-1])
# FUNCTIE!!!!
numeUtilizator.trace("w", lambda *args: length(numeUtilizator))
butonOk = Button(windows1, width="3", height="1", text="OK", font="arial 8 bold", bg="#70e5ee", command=succes)
butonOk.pack(anchor=CENTER)
windows1.mainloop()