0

I have two classes with produce two separate GUI windows. I am struggling to implement a situation where e.g. if a button is pressed in the first GUI, it adds a label to the second GUI after run-time. Could someone please provide me with a solution to this?

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()   
  • Read [Why are multiple instances of Tk discouraged?](https://stackoverflow.com/questions/48045401/why-are-multiple-instances-of-tk-discouraged) and [Tkinter understanding mainloop](https://stackoverflow.com/questions/29158220/tkinter-understanding-mainloop) – stovfl Dec 31 '19 at 11:42
  • When you want ot have multiple GUI windows, a good way to do it is to create [`tk.Toplevel`](https://web.archive.org/web/20190429194251id_/http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/toplevel.html) widgets for each one (and only call `tk.Tk()` once in the main portion of the script). In this case you could pass them as the `master` when creating the instances of your classes (instead of `root`). – martineau Dec 31 '19 at 12:10
  • Sorry. I don't think you understand the question. I want to have two separate GUIs as they are conceptually to be displayed on two separate monitors within a store. e.g. one monitor for customers and one monitor for Barista's – YieldedTemparz Dec 31 '19 at 12:17
  • As soon as the code runs on the same CPU (even if the 2 GUI windows are displayed on 2 different monitors) it is better to make one single call to `Tk()` for the main window (says, the one for the barista) and call `Toplevel()` for the other (the one for the customer). – sciroccorics Dec 31 '19 at 12:41
  • Are you expecting this code to be run in separate processes on separate machines? The way it is formatted it looks like you are trying to create two windows in a single process. – Bryan Oakley Dec 31 '19 at 14:59
  • This looks like a duplicate of [Python link two separate GUIs on physically different computers](https://stackoverflow.com/questions/59533932/python-link-two-separate-guis-on-physically-different-computers), just asked in a slightly different way. – Bryan Oakley Dec 31 '19 at 15:00

1 Answers1

0

Here is a sample code that creates the Barista and the Customer windows. The Customer window contain a Button, and each time you press this button, it increments the order counter and updates the Barista window. Is this the kind of stuff that you need?

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()
sciroccorics
  • 2,357
  • 1
  • 8
  • 21