Reputation: 235
The code below works perfect. However, what I noticed is that when I use withdraw()
and deiconify()
and then click on the x
close button of the window and try to run my code again, my visual studio IDE does not start up my program. I have to close the IDE and then open it again to make it work. This only happens when I am using withdraw()
and deiconify()
. Why is this happening?
***main.py***
import tkinter as tk
from tkinter import ttk
import subprocess
import time
from tkinter import*
from tkinter import messagebox
from log import mainDashboardWindow
def login():
try:
messagebox.showinfo("Success", "Login Successful!")
loginWindow.withdraw()
mainDashboardWindow(loginWindow,"session") #If successful login, display user dashboard
except:
messagebox.showerror("Message","Unable To Connect")
if __name__ == '__main__':
loginWindow = Tk()
loginWindow.title('Login')
loginWindow.geometry('925x500+300+200')
loginWindow.configure(bg="#fff")
loginWindow.resizable(False,False)
logonBtn = Button(loginWindow,width=43,pady=7,text='Login',bg='#57a1f8',fg='white',cursor='hand2',border=0,command= lambda : login()).place(x=30,y=230)
mainloop()
***log.py***
import tkinter as tk
from turtle import color, width
from tkinter import*
from tkinter import ttk
from tkinter import messagebox
def logout(dashboardWindow,loginWindow):
dashboardWindow.withdraw()
loginWindow.deiconify()
print("Logout of sap")
def mainDashboardWindow(loginWindow,session):
dashboardWindow = Tk()
dashboardWindow.title('Dashboard')
dashboardWindow.geometry('925x500+300+200')
dashboardWindow.configure(bg="#fff")
dashboardWindow.resizable(False,False)
logoutBtn = Button(dashboardWindow,width=19,pady=7,text='Logout',bg='#57a1f8',fg='white',cursor='hand2',border=0,command= lambda : logout(dashboardWindow,loginWindow))
logoutBtn.pack(padx=(0,30),pady=(30,30),side=tk.RIGHT)
Upvotes: 0
Views: 498
Reputation: 8037
Withdraw does not just iconify
your window it forces your window manager to forget about that window. This can be useful in some cases and in others you will receive unintended behavior. You should work with iconify
if withdraw
is not needed and or set the window in iconifyied state before deiconifying. The documentation states:
wm withdraw window Arranges for window to be withdrawn from the screen. This causes the window to be unmapped and forgotten about by the window manager. If the window has never been mapped, then this command causes the window to be mapped in the withdrawn state. Not all window managers appear to know how to handle windows that are mapped in the withdrawn state. Note: it sometimes seems to be necessary to withdraw a window and then re-map it (e.g. with wm deiconify) to get some window managers to pay attention to changes in window attributes such as group.
Upvotes: 1