1 year ago
#282391
ChronoVortex
weird issue with root.destroy() not working with .bind()
There seems to be a rather weird issue with the code I've been developing regarding tkinter's root.destroy()
method. It just doesn't seem to want to work with the .bind()
method. The other two bind functions works properly when changing the images, but root.destroy
just doesnt work regardless of how I tried to put it. I've tried putting it in a function and calling it, putting it in an anonymous function and replacing it with self.master.destroy
, nothing seems to work. The one that was called by the button does tho, only the key binding does not. Would appreciate some help on the matter, below is my code:
class ImageFrame:
def __init__(self, master):
self.master = master
master.title("Nothing sus move along")
#root.geometry("1920x1080")
master.config(bg="black")
master.resizable(False,False)
master.columnconfigure([0,3],weight=1)
master.rowconfigure([0,3],weight=1)
self.leftRightFrame = Frame(height=300)
self.leftRightFrame.grid(row=2,column=1)
self.image=Label(master, image=images[page])
self.image.grid(row=2,column=2)
self.nxtbtn = Button(self.leftRightFrame, text="Next(D)", bg='black', fg='red', width=5, font=('ariel 10 bold'), relief=GROOVE, command=self.snext)
self.nxtbtn.pack(side=TOP,ipady=50)
self.image.bind('d',self.snext)
self.backbtn = Button(self.leftRightFrame, text="Back(A)", bg='black', fg='red', width=5, font=('ariel 10 bold'), relief=GROOVE, command=self.sback)
self.backbtn.pack(side=BOTTOM,ipady=50)
self.image.bind('a',self.sback)
self.exitbtn = Button(master, text="Exit(Esc)", bg='black', fg='red', width=5, font=('ariel 10 bold'), relief=GROOVE, command=root.destroy)
self.exitbtn.grid(row=2,column=3)
self.image.bind('q',lambda e: root.destroy)
self.image.focus_set()
def snext(self,e):
global page
page+=1
if page>len(images)-1:
page=0
self.image.configure(image = images[page%len(images)])
def sback(self,e):
global page
page-=1
if page<0:
page=0
self.image.configure(image = images[page%len(images)])
def endwin(self,e):
self.master.destroy
print('Window terminated')
root = Tk()
mainWindow = ImageFrame(root)
root.mainloop()
The unrelated parts regarding image processing have been removed
python
tkinter
destroy
0 Answers
Your Answer