我是一個Python初學者做是應該保存和保留目前的campingsite(只是爲了好玩......)的程序。我以OOP方式構建它,這意味着我爲每個單獨的窗口定義一個類。我需要做的是更新一個顯示數據庫條目的TopLevel窗口(SubWindow2),當另一個TopLevel窗口(從Subwindow2創建)關閉時。Tkinter:先關閉另一個TopLevel窗口時更新TopLevel窗口? (參考?)
import Tkinter as tk
class MenuWindow(tk.Tk):
def __init__(self, master):
self.master = master
#Widgets
def open_subwindow1(self):
self.window = Toplevel(self.master)
self.SubSubWindow1 = SubSubWindow1(self.window)
def open_subwindow2(self):
self.window = Toplevel(self.master)
self.SubSubWindow2 = SubSubWindow2(self.window)
class SubWindow1(tk.Tk):
def __init__(self, master):
self.master = master
#Widgets
class Subwindow2(tk.TopLevel):
def __init__(self, master):
self.master = master
#Widgets
self.button = tk.Button(master, text='Quit', command=open_subsub1)
def load_values(self):
#loading sqlite db-values into listboxes
def open_subsub1(self):
self.window = Toplevel(self.master)
self.SubSubWindow1 = SubSubWindow1(self.window)
class SubSubWindow1(tk.TopLevel):
def __init__(self, master):
self.master = master
#Widgets
self.button = tk.Button(master, text='Quit', command=on_quit)
def on_quit(self):
#Here I want to call a function that updates SubWindow2 (loads sqlite database values into several listboxes)
self.master.destroy()
root = tk.Tk()
myprog = MyProg(root)
root.mainloop()
如何從SubSubWindow1訪問Subwindow2中的函數? self.master
只是指TopLevel()
實例吧?
def on_quit(self):
self.SubWindow2.load_values()
self.master.destroy()
不工作,我得到一個TypeError: unbound method load_values() must be called with SubWindow2 instance as first argument (got nothing instead)
這是一個unvalid計算策略,以「嵌套」的頂層窗口?有什麼選擇?
的任何言論都大大appriciated!感謝您的幫助
哇這個作品偉大的trank你!儘管我必須使用「self」作爲我的小部件(即幀)的父項,才能使它們顯示在頂部窗口而不是根窗口中!感謝您的幫助和努力 –