I am new to oop and I would like some assistance. I use a lambda to initalise the process of changing the frame, however I am unable to use the lambda inside of a function (method) in a class.
This is the lambda that normally works to change to the canteenpage:
lambda: controller.show_frame(CanteenPage)
I have been using this tutorial: https://www.youtube.com/watch?v=jBUpjijYtCk&t=4s&list=PLQVvvaa0QuDclKx-QpC9wntnURXVJqLyk&index=4
Original version of code :Switch between two frames in tkinter
code:
import tkinter as tk
from tkinter import ttk
class CashlessService(tk.Tk):
def __init__(self, *args, **kwards):
tk.Tk.__init__(self, *args, **kwards)
tk.Tk.wm_title(self, "CashlessService")
container = tk.Frame(self)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for i in (LoginPage, CanteenPage, AdminPage, StudentPage):
frame = i(container, self)
self.frames[i] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(LoginPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class LoginPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
#Button to confirm ID and password
ttk.Button(self, text="Login", command=self.LoginCheck).grid(row=4, column=1)
def LoginCheck(self):
login = True
if login == True:
lambda: controller.show_frame(CanteenPage)
class CanteenPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="canteen?", font=LARGE_FONT)
label.pack(pady=10, padx=10)
Sorry for the long request, I have been stuck on this for hours.
P.S no error message appears