Привет всем, я новичок в tkinter, и я попробовал все примеры для передачи значения из одного класса в другой класс в tkinter, но, похоже, не работает.Я хочу, чтобы поле ввода на моей странице входа отображалось как ярлык на моей домашней странице.Действительно оценит любую полученную помощь !!
class LoginPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
MyFrontend.configure(self, background="lightblue")
logo = tk.PhotoImage(file="logo.png")
tk.Label(self, image=logo).pack()
labelNric = tk.Label(self, text="NRIC:", font=LARGE_FONT_NOBOLD, background="lightblue", foreground="darkslategray")
labelNric.place(x=80,y=220)
# entry box for user input
entryNric = tk.Entry(self, highlightbackground="lightblue")
# entryNric.bind("<Return>", getNric)
entryNric.place(x=280,y=223)
labelEgnric = tk.Label(self, text="E.g. SXXXX123A", font=SMALL_FONT, background="lightblue", foreground="darkslategray")
labelEgnric.place(x=285,y=253)
def error_popupmsg(msg):
popup = tk.Tk()
popup.wm_title("Error")
popup.geometry("400x200")
popup.configure(background="darkred")
labelError = tk.Label(popup, text=msg, font=MED_FONT, background="darkred", foreground="white")
labelError.place(x=140, y=60)
buttonOk = tk.Button(popup, text="Got it!", highlightbackground ="#8B0000", command=popup.destroy)
buttonOk.place(x=170, y=100)
popup.mainloop()
def checkNric(arg=None):
nric_check = entryNric.get()
if nric_check == 'S1234567B' or nric_check == 'S1234567C':
controller.show_frame(HomePage)
else:
error_popupmsg("Invalid NRIC!")
buttonSubmit = ttk.Button(self, text="Submit", command=lambda: checkNric())
buttonSubmit.place(x=380,y=290)
class HomePage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
MyFrontend.configure(self, background="lightblue")
labelNricInfo = tk.Label(self, text="Patient's NRIC/FIN:", font=SMALL_FONT, background="lightblue", foreground="darkslategray")
labelNricInfo.place(x=50,y=40)
# to display NRIC from entry box in login page here
labelNricDisplay = tk.Label(self, text="", font=SMALL_FONT, foreground="darkslategray")
labelNricDisplay.place(x=170,y=40)
buttonBack = ttk.Button(self, text="Back", command=lambda: controller.show_frame(LoginPage))
buttonBack.place(x=370,y=420)
buttonSubmit = ttk.Button(self, text="Submit")
buttonSubmit.place(x=460,y=420)