Python Tkinter框架销毁
一般来说,我对python和编码都很陌生。我正在尝试为一个游戏制作一个应用程序,但我似乎无法破坏我创建的框架Python Tkinter框架销毁,tkinter,Tkinter,一般来说,我对python和编码都很陌生。我正在尝试为一个游戏制作一个应用程序,但我似乎无法破坏我创建的框架 from tkinter import * class application: def __init__(self,parent): self.startContainer = Frame(parent) self.startContainer.pack() self.lbl = Label(startContainer
from tkinter import *
class application:
def __init__(self,parent):
self.startContainer = Frame(parent)
self.startContainer.pack()
self.lbl = Label(startContainer,text="Please choose from the following: \nFaith Points (F) \nBanqueting Goods (B) \nEnter Honour (E) ")
self.lbl.pack()
self.btn1 = Button(startContainer,text="Votes",command=self.votes(startContainer)).pack()
self.btn2 = Button(startContainer,text="Gold Tithe",command=self.gold(startContainer)).pack()
def votes(parent,self):
parent.destroy()
def gold(parent,self):
pass
window = Tk()
app = application(window)
window.title("Tools")
window.geometry("425x375")
window.wm_iconbitmap("logo.ico")
window.resizable(width=False, height=False)
window.mainloop()
您正在主窗口内的小部件上调用destroy。 在“父级”上调用destroy。将父级转换为self.parent:调用self.voces()时,实际上是在调用函数,并且在函数打开之前将其销毁 此外,尝试将类内的函数参数构造为(self…)而不是(…,self)
您正在主窗口内的小部件上调用destroy。 在“父级”上调用destroy。将父级转换为self.parent:调用self.voces()时,实际上是在调用函数,并且在函数打开之前将其销毁 此外,尝试将类内的函数参数构造为(self…)而不是(…,self)
定义方法时,第一个参数应该是
self
。这适用于投票`和gold
方法。有关更多信息,请参见此。请注意,self
的命名只是一种约定,而不是保留字。定义方法时,第一个参数应该是self
。这适用于投票`和gold
方法。有关更多信息,请参见此。请注意,self
的命名只是一种约定,而不是保留字。
from tkinter import *
class application:
def __init__(self,parent):
self.parent = parent
startContainer = Frame(parent)
startContainer.pack()
self.lbl = Label(startContainer,text="Please choose from the following: \nFaith Points (F) \nBanqueting Goods (B) \nEnter Honour (E) ")
self.lbl.pack()
self.btn1 = Button(startContainer,text="Votes", command=self.votes).pack()
self.btn2 = Button(startContainer,text="Gold Tithe",command=self.gold(startContainer)).pack()
def votes(self):
print("test")
self.parent.destroy()
def gold(self, parent):
pass
window = Tk()
app = application(window)
window.mainloop()