Only open 1 window when button clicked multiple times

I am trying to create a basic invoicing system. However i have encountered an issue as you can tell from my the title, is there any way to achieve this. I have been using a counter to determine if the window should open or not but i dont think it is right.

from tkinter import *

window = Tk()
count = 0


def openNewWindow():
    global count

    count = count + 1

    if count == 1:

        newWindow = Toplevel(window)
        newWindow.title("New Window")
        newWindow.geometry("800x800")
        newWindow.title('test ©')  # Frame title
        newWindow.iconbitmap('icon4.ico')  # Frame logo
        

    if 'normal' == newWindow.state():
        count = 2

    else:
        count = 0


width = window.winfo_screenwidth()
height = window.winfo_screenheight()
window.geometry("%dx%d" % (width, height))

bg = PhotoImage(file="bsor.gif")
label_image = Label(window, image=bg)
label_image.place(x=0, y=0)

title_label = Label(window, text="Job Management System", bg="black", fg="white")
title_label.config(font=("Courier", 70))
title_label.place(x=65, y=3)

customer_database_button = Button(window, text="Customer Database", width="23", height="2", 
font=('Courier', 13, 'bold'), command=openNewWindow)
customer_database_button.grid(row=3, column=0, pady=185, padx=(110, 0))

employee_database_button = Button(window, text="Employee Database", width="23", height="2",
                              font=('Courier', 13, 'bold'))
employee_database_button.grid(row=3, column=1, pady=10, padx=(50, 0))

job_category_button = Button(window, text="Job Category (Pricing)", width="23", height="2",
                         font=('Courier', 13, 'bold'))
job_category_button.grid(row=3, column=2, pady=10, padx=(50, 0))

quote_sale_button = Button(window, text="Quotes / Sales", width="23", height="2", font= 
('Courier', 13, 'bold'))
quote_sale_button.grid(row=3, column=3, pady=10, padx=(50, 0))

cash_management_button = Button(window, text="Cash Management", width="23", height="2", font= 
('Courier', 13, 'bold'))
cash_management_button.grid(row=3, column=4, pady=10, padx=(50, 0))

analysis_mode_button = Button(window, text="Analysis Mode", width="23", height="2", font= 
('Courier', 13, 'bold'))
analysis_mode_button.grid(row=3, column=5, pady=10, padx=(50, 0))

window.title('test')  # Frame title
window.iconbitmap('icon4.ico')  # Frame logo

window.mainloop()

Source: Python-3x Questions

LEAVE A COMMENT