我正在开发具有3个窗口的python tkinter GUI应用程序。我成功创建了3个独立的窗口。但是不知道如何链接它们。不同的窗口有不同的操作。 Window-3是一个有点复杂的窗口,它继承自其他3个类。我不知道该怎么称呼这个班。有什么建议吗?
class Page(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
def show(self):
self.lift()
class Page1(Page):
def __init__(self, *args, **kwargs):
Page.__init__(self, *args, **kwargs)
label = tk.Label(self, text="This is page 1")
label.pack(side="top", fill="both", expand=True)
#page2 like page1
#page3 inherit from Page, GuiPart and ThreadedClient Classes!!
class GuiPart:
def __init__(self, master, queue, endCommand):
self.queue = queue
# Set up the GUI
console = tk.Button(master, text='Done', command=endCommand)
console.pack()
def processIncoming(self):
while self.queue.qsize():
try:
msg = self.queue.get(0)
print (msg)
except queue.Empty:
pass
class ThreadedClient:
def __init__(self, master):
self.master = master
# Create the queue
self.queue = queue.Queue()
# Set up the GUI part
self.gui = GuiPart(master, self.queue, self.endApplication)
# Set up the thread to do asynchronous I/O
self.running = 1
self.thread1 = threading.Thread(target=self.workerThread1)
self.thread1.start()
self.periodicCall()
def periodicCall(self):
self.gui.processIncoming()
if not self.running:
import sys
sys.exit(1)
self.master.after(100, self.periodicCall)
def workerThread1(self):
while self.running:
time.sleep(1)
msg = rand.random()
self.queue.put(msg)
def endApplication(self):
self.running = 0
#next page3 class is confusing one
class Page3(Page, GuiPart, ThreadedClient):
def __init__(self, *args, **kwargs):
Page.__init__(self, *args, **kwargs)
label = tk.Label(self, text="This is page 3")
label.pack(side="top", fill="both", expand=True)
GuiPart.__init__(self, master, queue, endCommand) #is it right way to call??
ThreadedClient.__init__(self, master)
#final class
class MainView(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
p1 = Page1(self)
p2 = Page2(self)
p3 = Page3(self) #------how to do this here
#rest of the code goes below this