I am aware there are answers on this website dealing with this issue but all resolutions that I've come across haven't seemed to help in my situation. I'm using Tkinter (and trying to learn how to use it) to make a game. I want a button (Quit Game) to exit out of the Tkinter window but I keep getting this error:
TypeError: exe() missing 1 required positional argument: 'self'
My code:
from tkinter import *
import sys as s, time as t
try: color = sys.stdout.shell
except AttributeError: raise RuntimeError("This programme can only be run in IDLE")
color.write(" | Game Console | \n", "STRING")
root = Tk()
root.title("Tic-Tac-Toe")
menuFrame = Frame(root)
menuFrame.pack()
buttonFrame = Frame(root)
buttonFrame.pack()
Label(menuFrame, text = ("Tic-Tac-Toe"), font = ("Helvetica 12 bold")).grid(row = 10, column = 5)
def play():
color.write("Game window opening... \n", "STRING")
#open new window to game later
def exe(self):
color.write("Goodbye for now \n", "STRING")
self.destroy()
playButton = Button(buttonFrame, text = ("Play game"), command = play)
playButton.pack(side=LEFT)
Button(root, text=("Quit Game"), command=exe).pack()
root.mainloop()
I can't seem to find where it means as I've defined it into the function. Thank you in advance for your solutions.
In your code you have:
This means you are requiring the
self
argument;self
is used with instances of a class and as your method does not have a class you can omit theself
parameter like so in your method header, like this: