I look here. I can split my page (frame) into two file. For example, this is my first file: main.py
from Tkinter import *
from halsatu import *
class Biasa(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
container = Frame(self)
container.pack(expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo):
frame = F(container, self)
frame.grid(row=0, column=0, sticky='news')
self.frames[F] = frame
self.show_frame(StartPage)
def show_frame(self, c):
frame = self.frames[c]
frame.tkraise()
class StartPage(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
label = Label(self, text='Ini halaman Awal')
label.pack()
button = Button(self, text='ke Halaman 1',
command=lambda: controller.show_frame(PageOne))
button.pack()
button2 = Button(self, text='ke Hal. 2',
command=lambda: controller.show_frame(PageTwo))
button2.pack()
class PageTwo(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
label = Label(self, text='Sekarang \nIni halaman Dua lho..')
label.pack()
button = Button(self, text='ke Halaman 1',
command=lambda: controller.show_frame(PageOne))
button.pack()
button2 = Button(self, text='ke Hal. Awal',
command=lambda: controller.show_frame(StartPage))
button2.pack()
if __name__ == '__main__':
app = Biasa()
app.mainloop()
Then this is my halsatu.py:
from Tkinter import *
class PageOne(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
label = Label(self, text='Kalau yang Ini halaman Satuuuuuuuuuuuuuuuuuu')
label.pack()
button = Button(self, text='ke Halaman Awal',
command=lambda: controller.show_frame(StartPage))
button.pack()
button2 = Button(self, text='ke Hal. 2',
command=lambda: controller.show_frame(PageTwo))
button2.pack()
That code can run. But when I go to pageone, I can't go back to StartPage again. How to split so many pages (frames) into separate files?