एक तरफ फ्रेम को एक-दूसरे के ऊपर ढेर करना है, तो आप केवल स्टैकिंग ऑर्डर में दूसरे से ऊपर उठा सकते हैं। शीर्ष पर एक वह दिखाई देगा जो दिखाई दे रहा है। यह सबसे अच्छा काम करता है अगर सभी फ्रेम एक ही आकार के होते हैं, लेकिन थोड़े से काम के साथ आप इसे किसी भी आकार के फ्रेम के साथ काम करने के लिए प्राप्त कर सकते हैं।
नोट: इस काम करने के लिए, एक पृष्ठ के लिए विगेट्स के सभी उस पृष्ठ होना चाहिए: (शब्दावली आप पसंद करते हैं पर निर्भर करता है, या गुरु) एक अभिभावक के रूप (यानी self
) या वंश। आप एक कक्षा में उदाहरण बनाकर भ्रामक की अवधारणा मिल जाए
import tkinter as tk # python 3
from tkinter import font as tkfont # python 3
#import Tkinter as tk # python 2
#import tkFont as tkfont # python 2
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")
# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
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 F in (StartPage, PageOne, PageTwo):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("StartPage")
def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is the start page", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
button1 = tk.Button(self, text="Go to Page One",
command=lambda: controller.show_frame("PageOne"))
button2 = tk.Button(self, text="Go to Page Two",
command=lambda: controller.show_frame("PageTwo"))
button1.pack()
button2.pack()
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is page 1", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Go to the start page",
command=lambda: controller.show_frame("StartPage"))
button.pack()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is page 2", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Go to the start page",
command=lambda: controller.show_frame("StartPage"))
button.pack()
if __name__ == "__main__":
app = SampleApp()
app.mainloop()



, या यदि विभिन्न पृष्ठों की जरूरत है:
यहाँ एक काल्पनिक उदाहरण का एक सा आप सामान्य अवधारणा को दिखाने के लिए है निर्माण के दौरान विभिन्न तर्क, आप स्पष्ट रूप से प्रत्येक वर्ग को अलग से कॉल कर सकते हैं। लूप मुख्य रूप से इस बिंदु को स्पष्ट करने के लिए कार्य करता है कि प्रत्येक वर्ग समान है।
उदाहरण के लिए, कक्षाएं बनाने के लिए व्यक्तिगत रूप से आप इस के साथ पाश (for F in (StartPage, ...)
निकाल सकते हैं:
self.frames["StartPage"] = StartPage(parent=container, controller=self)
self.frames["PageOne"] = PageOne(parent=container, controller=self)
self.frames["PageTwo"] = PageTwo(parent=container, controller=self)
self.frames["StartPage"].grid(row=0, column=0, sticky="nsew")
self.frames["PageOne"].grid(row=0, column=0, sticky="nsew")
self.frames["PageTwo"].grid(row=0, column=0, sticky="nsew")
समय लोगों से अधिक के लिए इस कोड (या एक ऑनलाइन ट्यूटोरियल है कि इस की नकल की का उपयोग कर अन्य प्रश्न पूछा है एक प्रारंभिक बिंदु के रूप code) आपने इन सवालों के जवाब को पढ़ने के लिए चाहते हो सकता है:।
वाह, बहुत बहुत धन्यवाद। एक व्यावहारिक के बजाय एक अकादमिक प्रश्न के रूप में, एक-दूसरे के ऊपर छिपे हुए इन पृष्ठों में से कितने पेजों को आपको लगी और अनुत्तरदायी बनना शुरू करने से पहले आवश्यकता होगी? –
मुझे नहीं पता। शायद हजारों।परीक्षण करने के लिए यह आसान होगा। –
@ ब्रायन ओकले महान जवाब, अगर मेरे पास एक वृक्षदृश्य है, उदाहरण के लिए, पेज दो और पृष्ठ में कुछ डेटा भरने पर अपडेट करना चाहते हैं तो मैं पृष्ठ में कोई विधि या फ़ंक्शन कैसे कॉल कर सकता हूं ट्रीव्यू को अपडेट करने के लिए दो। – diego