Reputation:
I am trying to create a login and sign up system using tkinter but have a problem which is that : every time I destroy an application in tkinter I am not able to use it again until I shut the program down and restart it.
Is there any way to get rid of an application temporarily so that I can use it later without having to restart the program?
Upvotes: 0
Views: 373
Reputation: 1257
I am not exactly sure how you are running the program but I hope this helps:
I created a main window that is like an application which has a button. When I click this button, another window pops up which asks for username and password. Once you click confirm it destroys the top window but main window is alive. You can click the button again and the username and password window pops up again!!
from tkinter import *
#Creating main window
root = Tk()
def Input_Box():
# creating a top window
master_2 = Toplevel(root)
#Textboxes
user_name = Entry(master_2)
user_name.grid(row = 1, column = 2)
pwd = Entry(master_2)
pwd.grid(row = 2, column = 2)
label_un = ttk.Label(master_2, text = "Username")
label_un.grid(row = 1, column = 1)
label_pwd = ttk.Label(master_2, text = "Password")
label_pwd.grid(row = 2, column = 1)
#Destroys the top window but keeps the main window
quit_button = Button(master_2, text = "Confirm", command = master_2.destroy)
quit_button.grid(row=3, column = 1)
master_2.mainloop()
call_button = Button(root, text='Enter Usrnm and pwd', command = Input_Box)
call_button.pack()
root.mainloop()
To access the entry values you can do something like this:
def retrieve_input():
input = user_name.get("1.0",'end-1c')
So essentially you have a main window and different interactive inputs can be used to trigger different function using command = func_name
Please share your code so that we can help you better!
Upvotes: 1