1

I'm pretty new to python and coding in general. I'm trying to make an application for a game and I can't seem to destroy the frame I created.

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()
Vortexan
  • 11
  • 1
  • 2
  • 1
    when defining methods, the first argument should be `self`. This applies to the methods votes` and `gold`. see this [link](http://stackoverflow.com/questions/2709821/what-is-the-purpose-of-self) for more information. Note that the naming of `self` is merely a convention, and not a reserved word. – arrethra Apr 11 '17 at 16:03

1 Answers1

0

You're calling the destroy on a widget inside the main window. Call the destroy on the "parent". Transform the parent into self.parent: when calling self.votes() you're actually calling the function and you'll be destroying the function before it will open.

Additionally, try structuring the function parameters inside a class as (self, ...) not (..., 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()
Stijn Van Daele
  • 285
  • 1
  • 14