【发布时间】:2020-10-31 03:46:09
【问题描述】:
基本上我想运行一个允许用户更改其凭据的代码(已经在开始时给出)。在这里,函数 def Uname_change()、def Password_change()、def PhoneNo_change() 和 def DOB_change() 试图做到这一点。
但是每个函数中的变量“a”(a 是从各种条目小部件上的 get() 函数获得的,如图所示)产生一个空字符串。我不明白为什么。
代码:
class ProfilePage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent, bg = 'light blue')
def show_profile():
def Uname_change():
Uname_change_window = tk.Tk()
label = tk.Label(Uname_change_window, text = 'Enter New UserName').pack()
NewUname = tk.StringVar()
entry = tk.Entry(Uname_change_window, textvariable = NewUname).pack()
confirm_button = tk.Button(Uname_change_window, text='Confirm', command= ).pack()
back_button = tk.Button(Uname_change_window, text='Back', command= lambda : Uname_change_window.destroy()).pack()
Uname_change_window.mainloop()
def Password_change():
Password_change_window = tk.Tk()
label = tk.Label(Password_change_window, text = 'Enter New Password').pack()
NewPassword = tk.StringVar()
entry = tk.Entry(Password_change_window, textvariable = NewPassword).pack()
def confirm():
a = NewPassword.get()
print(a)
#Write code for updation of database
Password_change_window.destroy()
confirm_button = tk.Button(Password_change_window, text='Confirm', command= confirm).pack()
back_button = tk.Button(Password_change_window, text='Back', command= lambda : Password_change_window.destroy()).pack()
def PhoneNo_change():
PhoneNo_change_window = tk.Tk()
label = tk.Label(PhoneNo_change_window, text = 'Enter New PhoneNumber').pack()
NewPhoneNo = tk.StringVar()
entry = tk.Entry(PhoneNo_change_window, textvariable = NewPhoneNo).pack()
def confirm():
a = NewPhoneNo.get()
print(a)
#Write code for updation of database
PhoneNo_change_window.destroy()
confirm_button = tk.Button(PhoneNo_change_window, text='Confirm', command= confirm).pack()
back_button = tk.Button(PhoneNo_change_window, text='Back', command= lambda : PhoneNo_change_window.destroy()).pack()
def DOB_change():
DOB_change_window = tk.Tk()
label = tk.Label(DOB_change_window, text = 'Enter New DateOfBirth').pack()
NewDOB = tk.StringVar()
entry = tk.Entry(DOB_change_window, textvariable = NewDOB).pack()
def confirm():
a = NewDOB.get()
print(a)
#Write code for updation of database
DOB_change_window.destroy()
confirm_button = tk.Button(DOB_change_window, text='Confirm', command= confirm).pack()
back_button = tk.Button(DOB_change_window, text='Back', command= lambda : DOB_change_window.destroy()).pack()
UserID_label = tk.Label(self, text = 'UserID').grid(row=2,column=0)
Uname_label = tk.Label(self, text = 'UserName').grid(row=3,column=0)
Uname_change_button = tk.Button(self, text = 'Edit', command = Uname_change).grid(row=3,column=2)#
Password_label = tk.Label(self, text = 'Password').grid(row=4,column=0)
Password_change_button = tk.Button(self, text = 'Edit', command = Password_change).grid(row=4,column=2)#
PhoneNo_label = tk.Label(self, text = 'PhoneNo').grid(row=5,column=0)
PhoneNo_change_button = tk.Button(self, text='Edit', command = PhoneNo_change).grid(row=5,column=2)#
DOB_label = tk.Label(self, text = 'DateOfBirth').grid(row=6,column=0)
DOB_change_button = tk.Button(self, text = 'Edit', command = DOB_change).grid(row=6,column=2)#
DOJ_label = tk.Label(self, text = 'DateOfJoining').grid(row=7,column=0)
show_button = tk.Button(self, text = 'Show', command = show_profile).grid(row=1,column=1)
【问题讨论】:
-
请尽量减少此代码,并使其运行。就目前而言,存在一些语法错误。如果您从多个函数中看到相同的行为,就本问题而言,我们只需要一个函数。
标签: tkinter tkinter-entry