root.destroy() 无法与 .bind() 一起使用的奇怪问题
我一直在开发的有关 tkinter 的 root.destroy() 方法的代码似乎存在一个相当奇怪的问题。它似乎只是不想使用 .bind()
方法。其他两个绑定函数在更改图像时可以正常工作,但是无论我如何尝试放置它,root.destroy
都不起作用。我尝试过将其放入函数中并调用它,将其放入匿名函数中并将其替换为 self.master.destroy ,似乎没有任何效果。通过按钮调用的那个可以,只有键绑定不可以。希望对此事有一些帮助,下面是我的代码:
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()
有关图像处理的不相关部分已被删除
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论