I have referred to this post Python tkinter: How can I ensure only ONE child window is created onclick and not a new window every time the button is clicked? but i couldn't get my code to work. Could anyone please help me?
from tkinter import *
import os
import sys
import _thread
from s2 import work
from s1 import work2
root = Tk()
root.resizable(width=False, height=False)
root.title("Sample tkinter")
root.geometry(r"550x550")
def open_entry():
os.system("data1.py")
def open_aisle():
os.system("data2.py")
def close_entry():
os.system("data10.py")
def close_aisle():
os.system("data20.py")
def run():
_thread.start_new_thread(work,())
_thread.start_new_thread(work2,())
def openNewWindow():
global createdb_btn
newWindow = Toplevel(root)
newWindow.resizable(width=False,height=False)
newWindow.title("New Window")
newWindow.geometry("300x300")
create_front = Button(newWindow,text="Entry DB",relief=FLAT,bg="black",fg="white",command=open_entry)
create_front.place(x=50,y=80)
create_aisle = Button(newWindow,text="Aisle DB",relief=FLAT,bg="black",fg="white",command=open_aisle)
create_aisle.place(x=145,y=80)
def openAnotherWindow():
global removedb_btn
otherWindow = Toplevel(root)
otherWindow.resizable(width=False,height=False)
otherWindow.title("New Window")
otherWindow.geometry("300x300")
remove_front = Button(otherWindow,text="Entry DB",relief=FLAT,bg="black",fg="white",command=close_entry)
remove_front.place(x=50,y=80)
remove_aisle = Button(otherWindow,text="Aisle DB",relief=FLAT,bg="black",fg="white",command=close_aisle)
remove_aisle.place(x=145,y=80)
removedb_btn = Button(root,text="Remove databases",relief=FLAT,bg="black",fg="white",state=DISABLED)
removedb_btn.place(x=380,y=120)
camera_btn = Button(root,text="Open Cams",relief=FLAT,bg="black",fg="white",command=run)
camera_btn.place(x=50,y=120)
createdb_btn = Button(root,text="Create databases",relief=FLAT,bg="black",fg="white",command=openNewWindow)
createdb_btn.place(x=205,y=120)
removedb_btn = Button(root,text="Remove databases",relief=FLAT,bg="black",fg="white",command=openAnotherWindow)
removedb_btn.place(x=380,y=120)
root.mainloop()
I am trying to achieve this in both the openNewWindow function and openAnotherWindow function.