脚本的目标:
- (3) 不同的窗口,每个都在自己的类中,具有自己的小部件和布局,是通过 Toplevel 和回调创建的。
- 当创建一个新的(顶层)窗口时,前一个窗口将被销毁。因此,一次只有一个窗口可见且处于活动状态。
问题?
基本上,我已经尝试了很多事情并且失败了,所以我必须了解太少["parent", "master", "root", "app", "..."]
:(
关于提升窗口的注意事项:
我已经实现了一个成功的示例,将所有框架相互叠加,并通过该.raise
方法控制它们的可见性。
但是,对于这个问题,我不想一次加载所有帧。这是一个测验程序的抽象版本,需要相当多的带有图像的帧,这让我不愿意一次加载所有内容。
脚本 (不工作;被窃听):
#!/usr/bin/env python
from Tkinter import *
import tkMessageBox, tkFont, random, ttk
class First_Window(Frame):
"""The option menu which is shown at startup"""
def __init__(self, master):
Frame.__init__(self, master)
self.gotosecond = Button(text = "Start", command = self.goto_Second)
self.gotosecond.grid(row = 2, column = 3, sticky = W+E)
def goto_Second(self):
self.master.withdraw()
self.master.update_idletasks()
Second_Window = Toplevel(self)
class Second_Window(Toplevel):
"""The gamewindow with questions, timer and entrywidget"""
def __init__(self, *args):
Toplevel.__init__(self)
self.focus_set()
self.gotothird = Button(text = "gameover", command = self.goto_Third)
self.gotothird.grid(row = 2, column = 3, sticky = W+E)
def goto_Third(self):
Third_Window = Toplevel(self)
self.destroy()
class Third_Window(Toplevel):
"""Highscores are shown with buttons to Startmenu"""
def __init__(self, *args):
Toplevel.__init__(self)
self.focus_set()
self.master = First_Window
self.gotofirst = Button(text = "startover", command = self.goto_First)
self.gotofirst.grid(row = 2, column = 3, sticky = W+E)
def goto_First(self):
self.master.update()
self.master.deiconify()
self.destroy()
def main():
root = Tk()
root.title("Algebra game by PJK")
app = First_Window(root)
root.resizable(FALSE,FALSE)
app.mainloop()
main()