我正在用Tkinter制作GUI,需要知道哪一帧在最上方,因此降低的帧之一不会进入其循环之一并更改某些设置。
我已经尝试过
self.tk.eval('frame stackorder '+str(self.frames["StartPage"])+' isabove '+str(self.frames["Wallpaper"]))=='1'
我是我的根源(属于一个班级),并且收到此错误
_tkinter.TclError: bad window path name "stackorder"
还
self.tk.eval('wm stackorder '+str(self.frames["StartPage"])
给我这个错误:
_tkinter.TclError: window ".!frame.!startpage" isn't a top-level window
这是我在帧之间创建和更改的方式
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()
我采取了从此处更改框架(Switch between two frames in tkinter)的方法,但是不知道如何知道最上面的那个。
答案 0 :(得分:0)
您可能应该保留对可见框架的引用,以便可以访问它:
class App(tk.Tk()):
def __init__(self, ...):
...
self.visible_frame = "StartPage"
...
def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()
self.visible_frame = page_name