Doot
Doot

Reputation: 63

TypeError: function missing 1 required positional argument

I'm doing a tic-tac-toe program and have to use Tkinter. The program used to do the code is "Pyzo".

I decided to implement separate functions for each of the following: winning condition, filling a cell, and clicking on a cell.

When I wanted to test the program, the console gave me the error:

 File "c:\users\[private]\appdata\local\programs\python\python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
TypeError: cases() missing 1 required positional argument

Here's the whole code :

    ## Importation des Modules ##
    from tkinter import 

    ## Création de la fenêtre / creating the sheet ##
    fen = Tk()
    fen.title('Game')
    text=Label(fen, text="Go ahead Mr Joestar")
    text.grid(row=0, column=0)
    pos=Label(fen, text='(Nope;Nope)')
    pos.grid(row=0, column=1)
    ##Liste / list ###
    list=[[0,0,0],[0,0,0],[0,0,0]]
    print(list)

    ##Variables##
    Joueur=1 #Joueur1 = 1 ; Joueur2 = -1 / player1=1 ; player2=-1
    V1=0#condition victoire j1 / Winning condition for player 1
    V2=0#condition victoire j2 / Winning condition for player 2
    IDC=0 #identifier la case / for identifying which cell
    
    ##Functions##
    def Position(event):
        pos.configure(text='('+str(event.x)+'.'+str(event.y)+')')
    
    def win(list): #pour voir qui a gagné / to see who won
        if list[0][0]+list[0][1]+list[0][2]==3: #Vérification lignes
            V1=1
        elif list[0][0]+list[0][1]+list[0][2]==-3:
            V2=1
        elif list[1][0]+list[1][1]+list[1][2]==3:
            V1=1
        elif list[1][0]+list[1][1]+list[1][2]==-3:
            V2=1
        elif list[2][0]+list[2][1]+list[2][2]==3:
            V1=1
        elif list[2][0]+list[2][1]+list[2][2]==-3:
            V2=1
        elif list[0][0]+list[1][0]+list[2][0]==3: #Vérification colones
            V1=1
        elif list[0][0]+list[1][0]+list[2][0]==-3:
            V2=1
        elif list[0][1]+list[1][1]+list[2][1]==3:
            V1=1
        elif list[0][1]+list[1][1]+list[2][1]==-3:
            V2=1
        elif list[0][0]+list[1][1]+list[2][2]==3:#Diagonales
            V1=1
        elif list[0][0]+list[1][1]+list[2][2]==-3:
            V2=1
        elif list[0][2]+list[1][1]+list[2][0]==3:
            V1=1
        elif list[0][2]+list[1][1]+list[2][0]==-3:
            V2=1
    
    def remplir(list,IDC):#pour remplir les cases
        if IDC ==1:
            if list[0][0]==0:
                list[0][0]=Joueur
                Canvas.create_line(10,10,90,90, width=1)
                Joueur=-Joueur
            elif list[0][0]!=0:
                print("case déjà prise")
    
    def cases(event,IDC):
        if int(event.x)>2 and int(event.x)<100 and int(event.y)>0 and int(event.y)<100: #CASE A1
            print('A1')
            IDC=1
            remplir(list,IDC)
            win(list)
        elif int(event.x)>102 and int(event.x)<200 and int(event.y)>0 and int(event.y)<100: #CASE A2
            print('A2')
        elif int(event.x)>202 and int(event.x)<300 and int(event.y)>0 and int(event.y)<100: #CASE A3
            print('A3')
        elif int(event.x)>2 and int(event.x)<100 and int(event.y)>100 and int(event.y)<200: #CASE B1
            print('B1')
        elif int(event.x)>100 and int(event.x)<200 and int(event.y)>102 and int(event.y)<200: #CASE B2
            print('B2')
        elif int(event.x)>202 and int(event.x)<300 and int(event.y)>102 and int(event.y)<200: #CASE B3
            print('B3')
        elif int(event.x)>2 and int(event.x)<100 and int(event.y)>202 and int(event.y)<300: #CASE C1
            print('C1')
        elif int(event.x)>100 and int(event.x)<200 and int(event.y)>202 and int(event.y)<300: #CASE C2
            print('C2')
        elif int(event.x)>202 and int(event.x)<300 and int(event.y)>202 and int(event.y)<300: #CASE C3
            print('C3')
        else:
            print('no')
    
    ##Fuctions:others##
    def restart(V1,V2):
        V1=0
        V2=0
        list=[[0,0,0],[0,0,0],[0,0,0]]
        Joueur=1
    
    ##buttons##
    bouton_quitter = Button(fen, text='Quitter', command=fen.destroy) #Quitter
    bouton_quitter.grid(row=2, column=0)
    
    bouton_restart = Button(fen, text='Recommencer', command=restart(V1,V2)) #Restart
    bouton_restart.grid(row=2, column=1)
    
    ##Canvas##
    dessin=Canvas(fen, bg="white", width=301, height=301) #canvas
    dessin.grid(row = 1, column = 0, padx=2, pady=2, columnspan=2) #Position Canvas
    
    dessin.create_line(99, 0, 99, 301, width=1, fill='black')
    dessin.create_line(201, 0, 201, 301, width=1, fill='black')
    dessin.create_line(0, 99, 301, 99, width=1, fill='black')
    dessin.create_line(0, 201, 301, 201, width=1, fill='black')
    
    ##Mainloop##
    dessin.bind("<Motion>", Position) #event motion mouse
    dessin.bind("<Button-1>", cases) #event mouse 1
    fen.mainloop()

Upvotes: 2

Views: 1962

Answers (2)

When you call dessin.bind("<Button-1>", cases) #event mouse 1 You haven't supplied the parameters to the function, your trying to call a function that requires parameters, without the parameters

Upvotes: 0

Parakiwi
Parakiwi

Reputation: 611

Try changing

def cases(event, IDC):

to

def cases(event):

There are some other syntax issues you will have to work through (as stated in the comments of this post) but this should get you started.

Upvotes: 3

Related Questions