I have a main window open. I don’t want to close this window. (which seems to be in most of these questions).
when I click on a button a small window opens under the mouse position. I want this second window to close when either one of its buttons are pressed or after the mouse moves away.
My problem is when I go into a function from either of the above actions I do not seem to have a reference to close this window. as in ‘alt.destroy’
My thought is to use the mouse moves away option as it should cover all needs.
Here is a sample code of what I am trying to do.
from tkinter import *
backGd='#333333'
FrGd='white'
def AlignmentTypes():
alt_x_y=ListWinStartPsn()
alt = Tk()
alt.geometry(f"100x150+{alt_x_y[0]}+{alt_x_y[1]+20}")
#alt.configure(bg=backGd)
alt.bind("<Leave>", closeAltWin)
Titlelabel=Label(alt, text="Select Alignment Type",bg=backGd,fg=FrGd)
alLeft_btn=Button(alt,text="Align Left",fg="Dark Blue",width=11)
alCenter_btn=Button(alt,text="Align Center",fg="Dark Blue",width=11)
alRight_btn=Button(alt,text="Align Right",fg="Dark Blue",width=11)
alJustify_btn=Button(alt,text="Align Justify",fg="Dark Blue",width=11)
Titlelabel.pack()
alLeft_btn.pack()
alCenter_btn.pack()
alRight_btn.pack()
alJustify_btn.pack()
def ListWinStartPsn():
x, y = btn1.winfo_rootx(), btn1.winfo_rooty()
return(x,y)
def closeAltWin(event):
pass
#alt.destroy
root = Tk()
root.title('Workopedia')
root.geometry('500x300')
frame1=Frame(root)
frame1.pack()
btn1=Button(frame1,text="click",command=AlignmentTypes)
btn1.pack()
frame2=Frame(root)
frame2.pack()
lbl1=Label(frame1,text="Stuff")
lbl1.pack()
root.mainloop()