单击“更改”按钮时,如何执行“更改用户名”功能?有解决办法吗?谢谢你。
这是代码:
teacherSetScreen = Tk()
teacherSetScreen.title("Teacher Home")
teacherSetScreen.geometry("300x130")
newUsername = StringVar(teacherSetScreen)
def changeUsername():
print("dgdfgf")
newName = newUsername.get()
if(validateUsername(newName)):
print("Username Changed!")
updateData("Username", newName)
else:
print("Invalid Username")
def changeUsernamePop():
popup = Toplevel()
labelNewUsername = Label(popup, text="New Username: ")
labelNewUsername.grid(row=0, column=0, pady=4)
entryNewUsername = Entry(popup, textvariable=newUsername)
entryNewUsername.grid(row=0, column=1)
buttonNewUsername = Button(popup, text="Change", command=changeUsername)
buttonNewUsername.grid(row=1, column=0, columnspan=3, padx=50)
labelUsername = Label(teacherSetScreen, text="Username: "+labelText["Username"])
labelUsername.grid(row=1, column=0, pady=4, columnspan=2, sticky=W)
changeUsername = Button(teacherSetScreen, text="Change Username", command=changeUsernamePop)
changeUsername.grid(row=1, column=3, pady=4, columnspan=3)
teacherSetScreen.mainloop()