The code for changing pages was derived from: Switch between two frames in tkinter
Hello, I've been trying to figure out how to convert this code for changing pages into something that I could use, but I had no luck with that :( . I've been trying to make these buttons not only switch page, but do 1 more simple command at the same time, I guess that somehow i should make 1 function that would do both things, instead of 2 separate functions, but I'm still quite new to python, and even more to tkinter and everytime when i try to change these buttons commands or functions i get some kind of error, it seems that i can't find a way to do it, could you help me with that? Thanks in advance.
Edit: I have deleted some some code which wasn't needed, rest is needed i think. As for my failed attempts, I will add some tries below this code.
from tkinter import *
class App(Tk):
def __init__(self):
Tk.__init__(self)
container = Frame(self)
container.pack(side="top", fill="both", expand = True)
self.frames = {}
for F in (StartPage, PageOne, PageTwo):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(Frame):
def __init__(self, parent, controller):
Frame.__init__(self,parent)
label = Label(self, text="Start Page")
label.pack(pady=10,padx=10)
button = Button(self, text="Visit Page 1",
command=lambda: controller.show_frame(PageOne))
button.pack()
class PageOne(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
label = Label(self, text="Page One!!!")
label.pack(pady=10,padx=10)
button1 = Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
app = App()
app.mainloop()
I've been trying to combines these 2 functions:
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
def calculate(self):
e1 = self.v1.get()
e2 = self.v2.get()
entry1 = int(self.entry1.get())
entry2 = int(self.entry2.get())
k = entry1 * entry2
print(k)
tried to make 1 function out of theses two:
def run_all(self, cont):
frame = self.frames[cont]
frame.tkraise()
e1 = self.v1.get()
e2 = self.v2.get()
entry1 = int(self.entry1.get())
entry2 = int(self.entry2.get())
k = entry1 * entry2
print(k)
Wasn't sure what to put under parameters. Also I tried changing this buttons command:
button = Button(self, text="Visit Page 1",
command=lambda: controller.show_frame(PageOne))
button.pack()
Tried to write this command with and without lambda, but nothing worked.