在 Tkinter 中 运行 时间后从另一个 GUI 编辑 GUI

Editing GUI from another GUI after run-time in Tkinter

我有两个 类,可以生成两个单独的 GUI windows。我正在努力实现一种情况,例如如果在第一个 GUI 中按下按钮,它会在 运行 时间后向第二个 GUI 添加标签。有人可以为我提供解决方案吗?

Class CustomerOrder:
    def __init__(self, master):
        self.master = master
        master.title("Customer Order GUI")

        self.completedButton1 = Label(master,text=" Place Order:")
        self.completedButton1.pack(side=TOP)

root = Tk()
my_gui = CustomerOrder(root)
root.mainloop()



class baristaPage(tk.Frame):

    def __init__(self, master):
        self.master = master
        master.title("baristaPage")

        self.baristaPage = Label(text="Barista Page")
        self.baristaPage.place(x=0,y=0)

        dashboard = Label(text="Customer Queue System")
        dashboard.place(x=0,y=80)

root = Tk()
my_gui = baristaPage(root)
root.mainloop()   

这是创建 Barista 和 Customer 的示例代码 windows。 Customer window 包含一个 Button,每次按下此按钮时,它都会增加订单计数器并更新 Barista window。这是您需要的东西吗?

from tkinter import *

class Customer(Toplevel):

    def __init__(self, master):
        Toplevel.__init__(self) # create the secondary window
        self.title("Customer")
        self.master = master
        self.counter = 0

        self.customer = Label(self, text="Customer Page", width=40)
        self.customer.pack(side=TOP)

        self.button = Button(self, text="Place Order:", command=self.order)
        self.button.pack(side=TOP)

        self.mainloop()

    def order(self):
        self.counter += 1
        self.master.dashboard['text'] = "Order number %s" % self.counter


class Barista(Tk):

    def __init__(self):
        Tk.__init__(self) # create the main window
        self.title("Barista")

        self.barista = Label(self, text="Barista Page", width=40)
        self.barista.pack(side=TOP)

        self.dashboard = Label(self, text="Customer Queue System")
        self.dashboard.pack(side=TOP)

        self.customer = Customer(self) # instantiate Customer window
        self.mainloop()

Barista()