-3

Here is my code:

class GUI(playGame):
    def __init__(self):                          

        import tkinter as tk
        home=tk.Tk()
        home.title("Tic Tac Toe")
        home.geometry("160x180")
        w,h=6,3


        self.c1r1=tk.Button(text='',width=w, height=h, command=lambda: userTurn(self.c1r1))
        self.c1r1.grid(column=1,row=1)
        home.mainloop()

So, userTurn has been defined in the parent class playGame but when I run this and click on the button c1r1, I get NameError: name 'userTurn' is not defined

Husun
  • 29
  • 1
  • 7

1 Answers1

0

You need to add a self to the function call. You probably should be calling super() in your init:

import tkinter as tk

class playGame():
    def userTurn(self,foo):
        pass

class GUI(playGame):
    def __init__(self):
        super().__init__()
        home=tk.Tk()
        home.title("Tic Tac Toe")
        home.geometry("160x180")
        w,h=6,3

        self.c1r1=tk.Button(text='',width=w, height=h, command=lambda: self.userTurn(self.c1r1))
        self.c1r1.grid(column=1,row=1)
        home.mainloop()
ktzr
  • 1,625
  • 1
  • 11
  • 25