Besoin d'aide en python fonction piocher d'un jeu de domino

Fermé
pydeveloppeur - 13 nov. 2021 à 16:18
yg_be Messages postés 22730 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024 - 13 nov. 2021 à 22:26
Bonjour,
Je suis en train de créer un jeu de domino sur python à l'aide du module Tkinter pour un projet jeu de société. Cependant j'ai un soucis au niveau de ma fonction piocher. Voici une partie du code que j'ai réalisé.
Ma fonction est rattachée à un bouton tout fonctionnait avant car j'avais mis au préalable "print(un mot)" pour tester et cela fonctionnait donc au niveau des boutons tout fonctionne mais le problème vient de la fonction.
Le but étant de piocher au hasard un des domino et de l'afficher sur la fenêtre tkinter. Toute aide est la bienvenue et m'aidera pour mon projet merci !

import tkinter as TK
from tkinter import Canvas #Pour éviter d'écrire TK.Canvas
from PIL import Image
import time as tm
import random as randint

domino=['.\domino\domino-0_0.PNG','.\domino\domino-1_0.PNG','\domino\domino-2_0.PNG','\domino\domino-3_0.PNG','\domino\domino-4_0.PNG','.\domino\domino-5_0.PNG','\domino\domino-6_0.PNG','.\domino\domino-1_1.PNG','.\domino\domino-1_2.PNG','.\domino\domino-1_3.PNG','.\domino\domino-1_4.PNG','.\domino\domino-1_5.PNG','.\domino\domino-1_6.PNG','.\domino\domino-2_2.PNG','.\domino\domino-2_3.PNG','.\domino\domino-2_4.PNG','.\domino\domino-2_5.PNG','.\domino\domino-2_6.PNG','.\domino\domino-3_3.PNG','.\domino\domino-3_4.PNG','.\domino\domino-3_5.PNG','.\domino\domino-3_6.PNG','.\domino\domino-4_4.PNG','.\domino\domino-4_5.PNG','.\domino\domino-4_6.PNG','.\domino\domino-5_5.PNG','.\domino\domino-5_6.PNG']



def PIOCHER(dominoafficher):
x=random.randint(0,27)
dominoafficher=PhotoImage(file=domino[x])
#Canevas.create_image(50,50, image=domnioafficher)
canvas.create_image(50,50,image=dominoafficher)



erreur affichée :
Exception in Tkinter callback
Traceback (most recent call last):
File "c:\users\leila\anaconda3\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:\Users\leila\OneDrive\Bureau\test_domino_test_13_11.py", line 45, in PIOCHER
x=random.randint(0,27)
NameError: name 'random' is not defined



Configuration: Windows / Firefox 94.0
A voir également:

7 réponses

Whismeril Messages postés 19030 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 27 avril 2024 931
13 nov. 2021 à 16:33
Bonjour
En Python, l’indentation est primordiale, or par défaut le site ne la conserve pas.
Pour la conserver il faut utiliser les balises de code. Voir ce petit tuto https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
On pourra commencer à essayer de t’aider quand tu auras reposté correctement ton code.

D’autre part poster ton code c’est très bien, mais il faut aussi décrire le problème.

0
pydeveloppeur Messages postés 10 Date d'inscription samedi 13 novembre 2021 Statut Membre Dernière intervention 13 novembre 2021
13 nov. 2021 à 16:59
0
Whismeril Messages postés 19030 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 27 avril 2024 931
13 nov. 2021 à 17:04
Si tu ne veux pas d’aide, y’a pas de problème….
0
pydeveloppeur Messages postés 10 Date d'inscription samedi 13 novembre 2021 Statut Membre Dernière intervention 13 novembre 2021
13 nov. 2021 à 17:10
Merci pour ta réponse,
Dans mon message j'ai précisé l'erreur si tu déroules en bas. Je souhaite choisir au hasard une photo de la liste domino parmi les 28 et l'afficher sur ma fenêtre principale mais l'erreur ci-dessous s'affiche



0
yg_be Messages postés 22730 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024 1 477 > pydeveloppeur Messages postés 10 Date d'inscription samedi 13 novembre 2021 Statut Membre Dernière intervention 13 novembre 2021
13 nov. 2021 à 17:37
bonjour,
as-tu pris le temps de lire le petit tuto suggéré par Whismeril (bonjour)?

tu pourrais simplifier ton programme et obtenir la même erreur:
import random as randint
x=random.randint(0,27)
print(x)

et corriger ainsi:
import random
x=random.randint(0,27)
print(x)
0
Whismeril Messages postés 19030 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 27 avril 2024 931
13 nov. 2021 à 17:38
tant que tu ne posteras pas ton code correctement, on ne t’aidera pas.
0
pydeveloppeur Messages postés 10 Date d'inscription samedi 13 novembre 2021 Statut Membre Dernière intervention 13 novembre 2021
13 nov. 2021 à 18:00
import tkinter as TK
from tkinter import Canvas #Pour éviter d'écrire TK.Canvas
from PIL import Image
import time as tm
import random

domino=['.\domino\domino-0_0.PNG','.\domino\domino-1_0.PNG','\domino\domino-2_0.PNG','\domino\domino-3_0.PNG','\domino\domino-4_0.PNG','.\domino\domino-5_0.PNG','\domino\domino-6_0.PNG','.\domino\domino-1_1.PNG','.\domino\domino-1_2.PNG','.\domino\domino-1_3.PNG','.\domino\domino-1_4.PNG','.\domino\domino-1_5.PNG','.\domino\domino-1_6.PNG','.\domino\domino-2_2.PNG','.\domino\domino-2_3.PNG','.\domino\domino-2_4.PNG','.\domino\domino-2_5.PNG','.\domino\domino-2_6.PNG','.\domino\domino-3_3.PNG','.\domino\domino-3_4.PNG','.\domino\domino-3_5.PNG','.\domino\domino-3_6.PNG','.\domino\domino-4_4.PNG','.\domino\domino-4_5.PNG','.\domino\domino-4_6.PNG','.\domino\domino-5_5.PNG','.\domino\domino-5_6.PNG']


def START(*args):
    print("start function")
    Domino = ['.\domino\domino-0_0.PNG','.\domino\domino-1_0.PNG','\domino\domino-2_0.PNG','\domino\domino-3_0.PNG','\domino\domino-4_0.PNG','.\domino\domino-5_0.PNG','\domino\domino-6_0.PNG','.\domino\domino-1_1.PNG','.\domino\domino-1_2.PNG','.\domino\domino-1_3.PNG','.\domino\domino-1_4.PNG','.\domino\domino-1_5.PNG','.\domino\domino-1_6.PNG','.\domino\domino-2_2.PNG','.\domino\domino-2_3.PNG','.\domino\domino-2_4.PNG','.\domino\domino-2_5.PNG','.\domino\domino-2_6.PNG','.\domino\domino-3_3.PNG','.\domino\domino-3_4.PNG','.\domino\domino-3_5.PNG','.\domino\domino-3_6.PNG','.\domino\domino-4_4.PNG','.\domino\domino-4_5.PNG','.\domino\domino-4_6.PNG','.\domino\domino-5_5.PNG','.\domino\domino-5_6.PNG']
    U1 = []
    Rnd_1 = []

    for j in range(6):
        while(1):
            idx = rnd.randint(1,27)
            if idx not in Rnd_1:
                U1.append(Pdmn(Domino[idx]))
                Rnd_1.append(idx)
                break

    U2 = []
    Rnd_2 = Rnd_1.copy()

    for j in range(6):
        while(1):
            idx = rnd.randint(1,27)
            if idx not in Rnd_2:
                U2.append(Pdmn(Domino[idx]))
                Rnd_2.append(idx)
                break
        photo=TK.PhotoImage(file=".\domino\domino-00.PNG") #ou 0_0
        photo.resize((40,40), Image.ANTIALIAS)
        canvas.create_image(100,300, image = photo)

    return

def ABANDON(*args):
    print("ABANDON")
    return

def PIOCHER(dominoafficher):
   x=random.randint(0, 27)
   dominoafficher=Image(file=domino[x])
   #Canevas.create_image(50,50, image=domnioafficher)
   canvas.create_image(50,50,image=dominoafficher)



def REJOUER(*args):
    print("REJOUER")
    return

def QUITTER(*args):
    global fen
    fen.destroy()



if __name__=='__main__':
    noms=[]
    for joueurs in range(2):
        def show():
            nom = Nom_du_joueur.get()
            noms.append(nom)
            #print(p)
            app.destroy()

        app = TK.Tk()
        app.title("Saisie nom des joueurs")
        app.geometry('400x400')
        canvas=TK.Canvas(background="#B0E0E6",height=300,width=300)
        img0=TK.PhotoImage(file="C:\\Users\\leila\\OneDrive\\Bureau\\joueur_image.PNG")
        canvas.create_image(150,150,image=img0)
        canvas.pack()
        Nom_du_joueur = TK.StringVar()
        nomEntry = TK.Entry(app, textvariable=Nom_du_joueur).pack()
        sumbmit = TK.Button(app, text='Saisir le nom des joueurs',command=show).pack()
        app.mainloop()

    print(noms)

fen = TK.Tk()
fen.title("Jeu de Domino")
canvas=Canvas(fen,width=600,height=600,background='#B0E0E6')

#1ère ligne du quadrillage
c11=Canvas.create_rectangle(canvas,100,100,140,140, fill="white")
c12=Canvas.create_rectangle(canvas,140,100,180,140, fill="white")
c13=Canvas.create_rectangle(canvas,180,100,220,140, fill="white")
c14=Canvas.create_rectangle(canvas,220,100,260,140, fill="white")
c15=Canvas.create_rectangle(canvas,260,100,300,140, fill="white")
c16=Canvas.create_rectangle(canvas,300,100,340,140, fill="white")
c17=Canvas.create_rectangle(canvas,340,100,380,140, fill="white")
c18=Canvas.create_rectangle(canvas,380,100,420,140, fill="white")
c19=Canvas.create_rectangle(canvas,420,100,460,140, fill="white")
c1A=Canvas.create_rectangle(canvas,460,100,500,140, fill="white")

#2ème ligne
c21=Canvas.create_rectangle(canvas,100,140,140,180, fill="white")
c22=Canvas.create_rectangle(canvas,140,140,180,180, fill="white")
c23=Canvas.create_rectangle(canvas,180,140,220,180, fill="white")
c24=Canvas.create_rectangle(canvas,220,140,260,180, fill="white")
c25=Canvas.create_rectangle(canvas,260,140,300,180, fill="white")
c26=Canvas.create_rectangle(canvas,300,140,340,180, fill="white")
c27=Canvas.create_rectangle(canvas,340,140,380,180, fill="white")
c28=Canvas.create_rectangle(canvas,380,140,420,180, fill="white")
c29=Canvas.create_rectangle(canvas,420,140,460,180, fill="white")
c2A=Canvas.create_rectangle(canvas,460,140,500,180, fill="white")

#3ème ligne
c31=Canvas.create_rectangle(canvas,100,180,140,220, fill="white")
c32=Canvas.create_rectangle(canvas,140,180,180,220, fill="white")
c33=Canvas.create_rectangle(canvas,180,180,220,220, fill="white")
c34=Canvas.create_rectangle(canvas,220,180,260,220, fill="white")
c35=Canvas.create_rectangle(canvas,260,180,300,220, fill="white")
c36=Canvas.create_rectangle(canvas,300,180,340,220, fill="white")
c37=Canvas.create_rectangle(canvas,340,180,380,220, fill="white")
c38=Canvas.create_rectangle(canvas,380,180,420,220, fill="white")
c39=Canvas.create_rectangle(canvas,420,180,460,220, fill="white")
c3A=Canvas.create_rectangle(canvas,460,180,500,220, fill="white")

#4ème ligne
c41=Canvas.create_rectangle(canvas,100,220,140,260, fill="white")
c42=Canvas.create_rectangle(canvas,140,220,180,260, fill="white")
c43=Canvas.create_rectangle(canvas,180,220,220,260, fill="white")
c44=Canvas.create_rectangle(canvas,220,220,260,260, fill="white")
c45=Canvas.create_rectangle(canvas,260,220,300,260, fill="white")
c46=Canvas.create_rectangle(canvas,300,220,340,260, fill="white")
c47=Canvas.create_rectangle(canvas,340,220,380,260, fill="white")
c48=Canvas.create_rectangle(canvas,380,220,420,260, fill="white")
c49=Canvas.create_rectangle(canvas,420,220,460,260, fill="white")
c4A=Canvas.create_rectangle(canvas,460,220,500,260, fill="white")

#5ème ligne
c51=Canvas.create_rectangle(canvas,100,260,140,300, fill="white")
c52=Canvas.create_rectangle(canvas,140,260,180,300, fill="white")
c53=Canvas.create_rectangle(canvas,180,260,220,300, fill="white")
c54=Canvas.create_rectangle(canvas,220,260,260,300, fill="white")
c55=Canvas.create_rectangle(canvas,260,260,300,300, fill="white")
c56=Canvas.create_rectangle(canvas,300,260,340,300, fill="white")
c57=Canvas.create_rectangle(canvas,340,260,380,300, fill="white")
c58=Canvas.create_rectangle(canvas,380,260,420,300, fill="white")
c59=Canvas.create_rectangle(canvas,420,260,460,300, fill="white")
c5A=Canvas.create_rectangle(canvas,460,260,500,300, fill="white")

#6ème ligne
c61=Canvas.create_rectangle(canvas,100,300,140,340, fill="white")
c62=Canvas.create_rectangle(canvas,140,300,180,340, fill="white")
c63=Canvas.create_rectangle(canvas,180,300,220,340, fill="white")
c64=Canvas.create_rectangle(canvas,220,300,260,340, fill="white")
c65=Canvas.create_rectangle(canvas,260,300,300,340, fill="white")
c66=Canvas.create_rectangle(canvas,300,300,340,340, fill="white")
c67=Canvas.create_rectangle(canvas,340,300,380,340, fill="white")
c68=Canvas.create_rectangle(canvas,380,300,420,340, fill="white")
c69=Canvas.create_rectangle(canvas,420,300,460,340, fill="white")
c6A=Canvas.create_rectangle(canvas,460,300,500,340, fill="white")

#7ème ligne
c71=Canvas.create_rectangle(canvas,100,340,140,380, fill="white")
c72=Canvas.create_rectangle(canvas,140,340,180,380, fill="white")
c73=Canvas.create_rectangle(canvas,180,340,220,380, fill="white")
c74=Canvas.create_rectangle(canvas,220,340,260,380, fill="white")
c75=Canvas.create_rectangle(canvas,260,340,300,380, fill="white")
c76=Canvas.create_rectangle(canvas,300,340,340,380, fill="white")
c77=Canvas.create_rectangle(canvas,340,340,380,380, fill="white")
c78=Canvas.create_rectangle(canvas,380,340,420,380, fill="white")
c79=Canvas.create_rectangle(canvas,420,340,460,380, fill="white")
c7A=Canvas.create_rectangle(canvas,460,340,500,380, fill="white")

#8ème ligne
c81=Canvas.create_rectangle(canvas,100,380,140,420, fill="white")
c82=Canvas.create_rectangle(canvas,140,380,180,420, fill="white")
c83=Canvas.create_rectangle(canvas,180,380,220,420, fill="white")
c84=Canvas.create_rectangle(canvas,220,380,260,420, fill="white")
c85=Canvas.create_rectangle(canvas,260,380,300,420, fill="white")
c86=Canvas.create_rectangle(canvas,300,380,340,420, fill="white")
c87=Canvas.create_rectangle(canvas,340,380,380,420, fill="white")
c88=Canvas.create_rectangle(canvas,380,380,420,420, fill="white")
c89=Canvas.create_rectangle(canvas,420,380,460,420, fill="white")
c8A=Canvas.create_rectangle(canvas,460,380,500,420, fill="white")

#9ème ligne
c91=Canvas.create_rectangle(canvas,100,420,140,460, fill="white")
c92=Canvas.create_rectangle(canvas,140,420,180,460, fill="white")
c93=Canvas.create_rectangle(canvas,180,420,220,460, fill="white")
c94=Canvas.create_rectangle(canvas,220,420,260,460, fill="white")
c95=Canvas.create_rectangle(canvas,260,420,300,460, fill="white")
c96=Canvas.create_rectangle(canvas,300,420,340,460, fill="white")
c97=Canvas.create_rectangle(canvas,340,420,380,460, fill="white")
c98=Canvas.create_rectangle(canvas,380,420,420,460, fill="white")
c99=Canvas.create_rectangle(canvas,420,420,460,460, fill="white")
c9A=Canvas.create_rectangle(canvas,460,420,500,460, fill="white")


#dernière ligne
cA1=Canvas.create_rectangle(canvas,100,460,140,500, fill="white")
cA2=Canvas.create_rectangle(canvas,140,460,180,500, fill="white")
cA3=Canvas.create_rectangle(canvas,180,460,220,500, fill="white")
cA4=Canvas.create_rectangle(canvas,220,460,260,500, fill="white")
cA5=Canvas.create_rectangle(canvas,260,460,300,500, fill="white")
cA6=Canvas.create_rectangle(canvas,300,460,340,500, fill="white")
cA7=Canvas.create_rectangle(canvas,340,460,380,500, fill="white")
cA8=Canvas.create_rectangle(canvas,380,460,420,500, fill="white")
cA9=Canvas.create_rectangle(canvas,420,460,460,500, fill="white")
cAA=Canvas.create_rectangle(canvas,460,460,500,500, fill="white")


Canvas.create_text(canvas, 50, 105, text="noms[0]")
Canvas.create_text(canvas, 550, 105, text="noms[1]")

d11=Canvas.create_rectangle(canvas,30,140,70,180, fill="white")
d12=Canvas.create_rectangle(canvas,30,190,70,230, fill="white")
d13=Canvas.create_rectangle(canvas,30,240,70,280, fill="white")
d14=Canvas.create_rectangle(canvas,30,290,70,330, fill="white")
d15=Canvas.create_rectangle(canvas,30,340,70,380, fill="white")
d16=Canvas.create_rectangle(canvas,30,390,70,430, fill="white")
d17=Canvas.create_rectangle(canvas,30,440,70,480, fill="white")

d21=Canvas.create_rectangle(canvas,530,140,570,180, fill="white")
d22=Canvas.create_rectangle(canvas,530,190,570,230, fill="white")
d23=Canvas.create_rectangle(canvas,530,240,570,280, fill="white")
d24=Canvas.create_rectangle(canvas,530,290,570,330, fill="white")
d25=Canvas.create_rectangle(canvas,530,340,570,380, fill="white")
d26=Canvas.create_rectangle(canvas,530,390,570,430, fill="white")
d27=Canvas.create_rectangle(canvas,530,440,570,480, fill="white")

#Ajouter le bouton start
B1=Canvas.create_rectangle(canvas,60,530,130,580, fill="#6db4bf", tags = "START-Button")
B2=Canvas.create_rectangle(canvas,160,530,230,580, fill="#6db4bf", tags = "ABANDON-Button")
B3=Canvas.create_oval(canvas,250,520,340,590, fill="#6db4bf", tags = "PIOCHER-Button")
B4=Canvas.create_rectangle(canvas,360,530,430,580, fill="#6db4bf", tags = "REJOUER-Button")
B5=Canvas.create_rectangle(canvas,460,530,530,580, fill="#6db4bf", tags = "QUITTER-Button")

font1=('Calibri',11,'bold')

#Ajouter le nom de chaque bouton

Canvas.create_text(canvas, 95, 555, text= "START",font=font1, fill="white", tags = "START-Button")
Canvas.create_text(canvas, 195, 555, text= "ABANDON",font=font1, fill="white", tags = "ABANDON-Button")
Canvas.create_text(canvas, 295, 555, text= "PIOCHER",font=font1, fill="white", tags = "PIOCHER-Button")
Canvas.create_text(canvas, 395, 555, text= "REJOUER",font=font1, fill="white", tags = "REJOUER-Button")
Canvas.create_text(canvas, 495, 555, text= "QUITTER",font=font1, fill="white", tags = "QUITTER-Button")
canvas.pack()


#Ajout des actions aux boutons
canvas.tag_bind("START-Button","<Button-1>",START)
canvas.tag_bind("ABANDON-Button","<Button-1>",ABANDON)
canvas.tag_bind("PIOCHER-Button","<Button-1>",PIOCHER)
canvas.tag_bind("REJOUER-Button","<Button-1>",REJOUER)
canvas.tag_bind("QUITTER-Button","<Button-1>",QUITTER)


#canvas.pack()
fen.mainloop()





0
pydeveloppeur Messages postés 10 Date d'inscription samedi 13 novembre 2021 Statut Membre Dernière intervention 13 novembre 2021
Modifié le 13 nov. 2021 à 18:14
Les messages se sont effacés mais random is not defined signifie que le module random n'est pas défini. Une personne m'a suggéré de remplacer import random as randint par import random cependant j'ai un autre problème que je n'arrive pas à résoudre maintenant : le module objet 'est pas appelé :

TypeError: 'module' object is not callable je ne comprend pas comment il faut procéder aurais-tu une idée ?
0
Whismeril Messages postés 19030 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 27 avril 2024 931
13 nov. 2021 à 18:03
Ok, comme ça on peut travailler.

Ton message d’erreur se termine donc par
NameError: name 'random' is not defined


A ton avis qu’est ce que cela veut dire?
0
pydeveloppeur Messages postés 10 Date d'inscription samedi 13 novembre 2021 Statut Membre Dernière intervention 13 novembre 2021
13 nov. 2021 à 18:06
Cela signifie que le random n'est pas défini.
J'ai remplacé import random as randint par import random comme une personne me l'a conseillé mais désormais j'ai une seconde erreur : TypeError: 'module' object is not callable
Le module "objet" n'est pas appelé, je ne vois pas mon erreur aurais-tu une idée.
0
pydeveloppeur Messages postés 10 Date d'inscription samedi 13 novembre 2021 Statut Membre Dernière intervention 13 novembre 2021
13 nov. 2021 à 18:08
import tkinter as TK
from tkinter import Canvas #Pour éviter d'écrire TK.Canvas
from PIL import Image
import time as tm
import random

domino=['.\domino\domino-0_0.PNG','.\domino\domino-1_0.PNG','\domino\domino-2_0.PNG','\domino\domino-3_0.PNG','\domino\domino-4_0.PNG','.\domino\domino-5_0.PNG','\domino\domino-6_0.PNG','.\domino\domino-1_1.PNG','.\domino\domino-1_2.PNG','.\domino\domino-1_3.PNG','.\domino\domino-1_4.PNG','.\domino\domino-1_5.PNG','.\domino\domino-1_6.PNG','.\domino\domino-2_2.PNG','.\domino\domino-2_3.PNG','.\domino\domino-2_4.PNG','.\domino\domino-2_5.PNG','.\domino\domino-2_6.PNG','.\domino\domino-3_3.PNG','.\domino\domino-3_4.PNG','.\domino\domino-3_5.PNG','.\domino\domino-3_6.PNG','.\domino\domino-4_4.PNG','.\domino\domino-4_5.PNG','.\domino\domino-4_6.PNG','.\domino\domino-5_5.PNG','.\domino\domino-5_6.PNG']


def START(*args):
    print("start function")
    Domino = ['.\domino\domino-0_0.PNG','.\domino\domino-1_0.PNG','\domino\domino-2_0.PNG','\domino\domino-3_0.PNG','\domino\domino-4_0.PNG','.\domino\domino-5_0.PNG','\domino\domino-6_0.PNG','.\domino\domino-1_1.PNG','.\domino\domino-1_2.PNG','.\domino\domino-1_3.PNG','.\domino\domino-1_4.PNG','.\domino\domino-1_5.PNG','.\domino\domino-1_6.PNG','.\domino\domino-2_2.PNG','.\domino\domino-2_3.PNG','.\domino\domino-2_4.PNG','.\domino\domino-2_5.PNG','.\domino\domino-2_6.PNG','.\domino\domino-3_3.PNG','.\domino\domino-3_4.PNG','.\domino\domino-3_5.PNG','.\domino\domino-3_6.PNG','.\domino\domino-4_4.PNG','.\domino\domino-4_5.PNG','.\domino\domino-4_6.PNG','.\domino\domino-5_5.PNG','.\domino\domino-5_6.PNG']
    U1 = []
    Rnd_1 = []

    for j in range(6):
        while(1):
            idx = rnd.randint(1,27)
            if idx not in Rnd_1:
                U1.append(Pdmn(Domino[idx]))
                Rnd_1.append(idx)
                break

    U2 = []
    Rnd_2 = Rnd_1.copy()

    for j in range(6):
        while(1):
            idx = rnd.randint(1,27)
            if idx not in Rnd_2:
                U2.append(Pdmn(Domino[idx]))
                Rnd_2.append(idx)
                break
        photo=TK.PhotoImage(file=".\domino\domino-00.PNG") #ou 0_0
        photo.resize((40,40), Image.ANTIALIAS)
        canvas.create_image(100,300, image = photo)

    return

def ABANDON(*args):
    print("ABANDON")
    return

def PIOCHER(dominoafficher):
   x=random.randint(0, 27)
   dominoafficher=Image(file=domino[x])
   #Canevas.create_image(50,50, image=domnioafficher)
   canvas.create_image(50,50,image=dominoafficher)



def REJOUER(*args):
    print("REJOUER")
    return

def QUITTER(*args):
    global fen
    fen.destroy()



if __name__=='__main__':
    noms=[]
    for joueurs in range(2):
        def show():
            nom = Nom_du_joueur.get()
            noms.append(nom)
            #print(p)
            app.destroy()

        app = TK.Tk()
        app.title("Saisie nom des joueurs")
        app.geometry('400x400')
        canvas=TK.Canvas(background="#B0E0E6",height=300,width=300)
        img0=TK.PhotoImage(file="C:\\Users\\leila\\OneDrive\\Bureau\\joueur_image.PNG")
        canvas.create_image(150,150,image=img0)
        canvas.pack()
        Nom_du_joueur = TK.StringVar()
        nomEntry = TK.Entry(app, textvariable=Nom_du_joueur).pack()
        sumbmit = TK.Button(app, text='Saisir le nom des joueurs',command=show).pack()
        app.mainloop()

    print(noms)

fen = TK.Tk()
fen.title("Jeu de Domino")
canvas=Canvas(fen,width=600,height=600,background='#B0E0E6')

#1ère ligne du quadrillage
c11=Canvas.create_rectangle(canvas,100,100,140,140, fill="white")
c12=Canvas.create_rectangle(canvas,140,100,180,140, fill="white")
c13=Canvas.create_rectangle(canvas,180,100,220,140, fill="white")
c14=Canvas.create_rectangle(canvas,220,100,260,140, fill="white")
c15=Canvas.create_rectangle(canvas,260,100,300,140, fill="white")
c16=Canvas.create_rectangle(canvas,300,100,340,140, fill="white")
c17=Canvas.create_rectangle(canvas,340,100,380,140, fill="white")
c18=Canvas.create_rectangle(canvas,380,100,420,140, fill="white")
c19=Canvas.create_rectangle(canvas,420,100,460,140, fill="white")
c1A=Canvas.create_rectangle(canvas,460,100,500,140, fill="white")

#2ème ligne
c21=Canvas.create_rectangle(canvas,100,140,140,180, fill="white")
c22=Canvas.create_rectangle(canvas,140,140,180,180, fill="white")
c23=Canvas.create_rectangle(canvas,180,140,220,180, fill="white")
c24=Canvas.create_rectangle(canvas,220,140,260,180, fill="white")
c25=Canvas.create_rectangle(canvas,260,140,300,180, fill="white")
c26=Canvas.create_rectangle(canvas,300,140,340,180, fill="white")
c27=Canvas.create_rectangle(canvas,340,140,380,180, fill="white")
c28=Canvas.create_rectangle(canvas,380,140,420,180, fill="white")
c29=Canvas.create_rectangle(canvas,420,140,460,180, fill="white")
c2A=Canvas.create_rectangle(canvas,460,140,500,180, fill="white")

#3ème ligne
c31=Canvas.create_rectangle(canvas,100,180,140,220, fill="white")
c32=Canvas.create_rectangle(canvas,140,180,180,220, fill="white")
c33=Canvas.create_rectangle(canvas,180,180,220,220, fill="white")
c34=Canvas.create_rectangle(canvas,220,180,260,220, fill="white")
c35=Canvas.create_rectangle(canvas,260,180,300,220, fill="white")
c36=Canvas.create_rectangle(canvas,300,180,340,220, fill="white")
c37=Canvas.create_rectangle(canvas,340,180,380,220, fill="white")
c38=Canvas.create_rectangle(canvas,380,180,420,220, fill="white")
c39=Canvas.create_rectangle(canvas,420,180,460,220, fill="white")
c3A=Canvas.create_rectangle(canvas,460,180,500,220, fill="white")

#4ème ligne
c41=Canvas.create_rectangle(canvas,100,220,140,260, fill="white")
c42=Canvas.create_rectangle(canvas,140,220,180,260, fill="white")
c43=Canvas.create_rectangle(canvas,180,220,220,260, fill="white")
c44=Canvas.create_rectangle(canvas,220,220,260,260, fill="white")
c45=Canvas.create_rectangle(canvas,260,220,300,260, fill="white")
c46=Canvas.create_rectangle(canvas,300,220,340,260, fill="white")
c47=Canvas.create_rectangle(canvas,340,220,380,260, fill="white")
c48=Canvas.create_rectangle(canvas,380,220,420,260, fill="white")
c49=Canvas.create_rectangle(canvas,420,220,460,260, fill="white")
c4A=Canvas.create_rectangle(canvas,460,220,500,260, fill="white")

#5ème ligne
c51=Canvas.create_rectangle(canvas,100,260,140,300, fill="white")
c52=Canvas.create_rectangle(canvas,140,260,180,300, fill="white")
c53=Canvas.create_rectangle(canvas,180,260,220,300, fill="white")
c54=Canvas.create_rectangle(canvas,220,260,260,300, fill="white")
c55=Canvas.create_rectangle(canvas,260,260,300,300, fill="white")
c56=Canvas.create_rectangle(canvas,300,260,340,300, fill="white")
c57=Canvas.create_rectangle(canvas,340,260,380,300, fill="white")
c58=Canvas.create_rectangle(canvas,380,260,420,300, fill="white")
c59=Canvas.create_rectangle(canvas,420,260,460,300, fill="white")
c5A=Canvas.create_rectangle(canvas,460,260,500,300, fill="white")

#6ème ligne
c61=Canvas.create_rectangle(canvas,100,300,140,340, fill="white")
c62=Canvas.create_rectangle(canvas,140,300,180,340, fill="white")
c63=Canvas.create_rectangle(canvas,180,300,220,340, fill="white")
c64=Canvas.create_rectangle(canvas,220,300,260,340, fill="white")
c65=Canvas.create_rectangle(canvas,260,300,300,340, fill="white")
c66=Canvas.create_rectangle(canvas,300,300,340,340, fill="white")
c67=Canvas.create_rectangle(canvas,340,300,380,340, fill="white")
c68=Canvas.create_rectangle(canvas,380,300,420,340, fill="white")
c69=Canvas.create_rectangle(canvas,420,300,460,340, fill="white")
c6A=Canvas.create_rectangle(canvas,460,300,500,340, fill="white")

#7ème ligne
c71=Canvas.create_rectangle(canvas,100,340,140,380, fill="white")
c72=Canvas.create_rectangle(canvas,140,340,180,380, fill="white")
c73=Canvas.create_rectangle(canvas,180,340,220,380, fill="white")
c74=Canvas.create_rectangle(canvas,220,340,260,380, fill="white")
c75=Canvas.create_rectangle(canvas,260,340,300,380, fill="white")
c76=Canvas.create_rectangle(canvas,300,340,340,380, fill="white")
c77=Canvas.create_rectangle(canvas,340,340,380,380, fill="white")
c78=Canvas.create_rectangle(canvas,380,340,420,380, fill="white")
c79=Canvas.create_rectangle(canvas,420,340,460,380, fill="white")
c7A=Canvas.create_rectangle(canvas,460,340,500,380, fill="white")

#8ème ligne
c81=Canvas.create_rectangle(canvas,100,380,140,420, fill="white")
c82=Canvas.create_rectangle(canvas,140,380,180,420, fill="white")
c83=Canvas.create_rectangle(canvas,180,380,220,420, fill="white")
c84=Canvas.create_rectangle(canvas,220,380,260,420, fill="white")
c85=Canvas.create_rectangle(canvas,260,380,300,420, fill="white")
c86=Canvas.create_rectangle(canvas,300,380,340,420, fill="white")
c87=Canvas.create_rectangle(canvas,340,380,380,420, fill="white")
c88=Canvas.create_rectangle(canvas,380,380,420,420, fill="white")
c89=Canvas.create_rectangle(canvas,420,380,460,420, fill="white")
c8A=Canvas.create_rectangle(canvas,460,380,500,420, fill="white")

#9ème ligne
c91=Canvas.create_rectangle(canvas,100,420,140,460, fill="white")
c92=Canvas.create_rectangle(canvas,140,420,180,460, fill="white")
c93=Canvas.create_rectangle(canvas,180,420,220,460, fill="white")
c94=Canvas.create_rectangle(canvas,220,420,260,460, fill="white")
c95=Canvas.create_rectangle(canvas,260,420,300,460, fill="white")
c96=Canvas.create_rectangle(canvas,300,420,340,460, fill="white")
c97=Canvas.create_rectangle(canvas,340,420,380,460, fill="white")
c98=Canvas.create_rectangle(canvas,380,420,420,460, fill="white")
c99=Canvas.create_rectangle(canvas,420,420,460,460, fill="white")
c9A=Canvas.create_rectangle(canvas,460,420,500,460, fill="white")


#dernière ligne
cA1=Canvas.create_rectangle(canvas,100,460,140,500, fill="white")
cA2=Canvas.create_rectangle(canvas,140,460,180,500, fill="white")
cA3=Canvas.create_rectangle(canvas,180,460,220,500, fill="white")
cA4=Canvas.create_rectangle(canvas,220,460,260,500, fill="white")
cA5=Canvas.create_rectangle(canvas,260,460,300,500, fill="white")
cA6=Canvas.create_rectangle(canvas,300,460,340,500, fill="white")
cA7=Canvas.create_rectangle(canvas,340,460,380,500, fill="white")
cA8=Canvas.create_rectangle(canvas,380,460,420,500, fill="white")
cA9=Canvas.create_rectangle(canvas,420,460,460,500, fill="white")
cAA=Canvas.create_rectangle(canvas,460,460,500,500, fill="white")


Canvas.create_text(canvas, 50, 105, text="noms[0]")
Canvas.create_text(canvas, 550, 105, text="noms[1]")

d11=Canvas.create_rectangle(canvas,30,140,70,180, fill="white")
d12=Canvas.create_rectangle(canvas,30,190,70,230, fill="white")
d13=Canvas.create_rectangle(canvas,30,240,70,280, fill="white")
d14=Canvas.create_rectangle(canvas,30,290,70,330, fill="white")
d15=Canvas.create_rectangle(canvas,30,340,70,380, fill="white")
d16=Canvas.create_rectangle(canvas,30,390,70,430, fill="white")
d17=Canvas.create_rectangle(canvas,30,440,70,480, fill="white")

d21=Canvas.create_rectangle(canvas,530,140,570,180, fill="white")
d22=Canvas.create_rectangle(canvas,530,190,570,230, fill="white")
d23=Canvas.create_rectangle(canvas,530,240,570,280, fill="white")
d24=Canvas.create_rectangle(canvas,530,290,570,330, fill="white")
d25=Canvas.create_rectangle(canvas,530,340,570,380, fill="white")
d26=Canvas.create_rectangle(canvas,530,390,570,430, fill="white")
d27=Canvas.create_rectangle(canvas,530,440,570,480, fill="white")

#Ajouter le bouton start
B1=Canvas.create_rectangle(canvas,60,530,130,580, fill="#6db4bf", tags = "START-Button")
B2=Canvas.create_rectangle(canvas,160,530,230,580, fill="#6db4bf", tags = "ABANDON-Button")
B3=Canvas.create_oval(canvas,250,520,340,590, fill="#6db4bf", tags = "PIOCHER-Button")
B4=Canvas.create_rectangle(canvas,360,530,430,580, fill="#6db4bf", tags = "REJOUER-Button")
B5=Canvas.create_rectangle(canvas,460,530,530,580, fill="#6db4bf", tags = "QUITTER-Button")

font1=('Calibri',11,'bold')

#Ajouter le nom de chaque bouton

Canvas.create_text(canvas, 95, 555, text= "START",font=font1, fill="white", tags = "START-Button")
Canvas.create_text(canvas, 195, 555, text= "ABANDON",font=font1, fill="white", tags = "ABANDON-Button")
Canvas.create_text(canvas, 295, 555, text= "PIOCHER",font=font1, fill="white", tags = "PIOCHER-Button")
Canvas.create_text(canvas, 395, 555, text= "REJOUER",font=font1, fill="white", tags = "REJOUER-Button")
Canvas.create_text(canvas, 495, 555, text= "QUITTER",font=font1, fill="white", tags = "QUITTER-Button")
canvas.pack()


#Ajout des actions aux boutons
canvas.tag_bind("START-Button","<Button-1>",START)
canvas.tag_bind("ABANDON-Button","<Button-1>",ABANDON)
canvas.tag_bind("PIOCHER-Button","<Button-1>",PIOCHER)
canvas.tag_bind("REJOUER-Button","<Button-1>",REJOUER)
canvas.tag_bind("QUITTER-Button","<Button-1>",QUITTER)


#canvas.pack()
fen.mainloop()





0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Whismeril Messages postés 19030 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 27 avril 2024 931
13 nov. 2021 à 18:14
Ha oui, je n’avais pas vu le message de yg_be, que je salue au passage.
Comprends tu pourquoi, il fallait faire cette correction ?

is not callable ne veut pas dire que le module n’est pas appelé, mais qu’on ne peut pas l’appeler.
Peux tu copier coller le message d’erreur entier?
0
pydeveloppeur Messages postés 10 Date d'inscription samedi 13 novembre 2021 Statut Membre Dernière intervention 13 novembre 2021
13 nov. 2021 à 18:15
Voici le message d'erreur :


Exception in Tkinter callback
Traceback (most recent call last):
File "c:\users\leila\anaconda3\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:\Users\leila\OneDrive\Bureau\test_domino_test_13_11.py", line 46, in PIOCHER
dominoafficher=Image(file=domino[x])
TypeError: 'module' object is not callable
0
yg_be Messages postés 22730 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024 1 477 > pydeveloppeur Messages postés 10 Date d'inscription samedi 13 novembre 2021 Statut Membre Dernière intervention 13 novembre 2021
13 nov. 2021 à 19:19
dans le code que tu as montré au départ, tu avais
dominoafficher=PhotoImage(file=domino[x])

pourquoi l'as-tu modifié?
0
yg_be Messages postés 22730 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024 1 477
13 nov. 2021 à 19:29
'module' object is not callable

Image
étant un objet de type 'module', il ne peut pas être appelé.
0
pydeveloppeur Messages postés 10 Date d'inscription samedi 13 novembre 2021 Statut Membre Dernière intervention 13 novembre 2021 > yg_be Messages postés 22730 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024
Modifié le 13 nov. 2021 à 19:31
Merci beaucoup ! J'ai ré affiché PhotoImage cela fonctionne mais il y a un problème au niveau du chemin pourtant j'ai écrit le bon chemin dans ma liste; tous les fichiers PNG sont classés dans un fichier domino sur mon bureau.

Voici le message d'erreur : couldn't open ".\domino\domino-4_5.PNG": no such file or directory
Voic le code de ma liste :



domino=['.\domino\domino-0_0.PNG','.\domino\domino-1_0.PNG','\domino\domino-2_0.PNG','\domino\domino-3_0.PNG','\domino\domino-4_0.PNG','.\domino\domino-5_0.PNG','\domino\domino-6_0.PNG','.\domino\domino-1_1.PNG','.\domino\domino-1_2.PNG','.\domino\domino-1_3.PNG','.\domino\domino-1_4.PNG','.\domino\domino-1_5.PNG','.\domino\domino-1_6.PNG','.\domino\domino-2_2.PNG','.\domino\domino-2_3.PNG','.\domino\domino-2_4.PNG','.\domino\domino-2_5.PNG','.\domino\domino-2_6.PNG','.\domino\domino-3_3.PNG','.\domino\domino-3_4.PNG','.\domino\domino-3_5.PNG','.\domino\domino-3_6.PNG','.\domino\domino-4_4.PNG','.\domino\domino-4_5.PNG','.\domino\domino-4_6.PNG','.\domino\domino-5_5.PNG','.\domino\domino-5_6.PNG']
0
yg_be Messages postés 22730 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024 1 477 > pydeveloppeur Messages postés 10 Date d'inscription samedi 13 novembre 2021 Statut Membre Dernière intervention 13 novembre 2021
13 nov. 2021 à 21:06
pourquoi penses-tu que c'est le bon chemin pour accéder au bureau?

j'ai l'impression que tu as fait ce programme au hasard, sans trop le comprendre, et puis que tu viens nous demander comment le corriger.

pourquoi fais-tu ce travail?
0
Whismeril Messages postés 19030 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 27 avril 2024 931
13 nov. 2021 à 18:31
0
yg_be Messages postés 22730 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 26 avril 2024 1 477
13 nov. 2021 à 19:30
Je pense que PIL n'est pas utilisé, le plus simple serait de supprimer l'import de PIL.
0
Whismeril Messages postés 19030 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 27 avril 2024 931
13 nov. 2021 à 20:22
@yg_bee

Je pense que PIL n'est pas utilisé, le plus simple serait de supprimer l'import de PIL.

je t'avoue que PIL m'est étranger, Python c'est vraiment pas mon fort, je n'en fais que sur le forum....
J'ai juste cherché l'origine de son message d'erreur, en supposant que cela venait d'Image, lui-même issu de PIL.
Comme dans la doc que j'ai trouvée ça ne s'utilise pas comme pydeveloppeur l'a écrit, je lui ai donné le lien à lire.


@pydeveloppeur en prenant en considération le début de cette réponse, je ne suis pas certain de l'effet du point dans le chemin relatif (et une recherche rapide sur le net ne m'a pas apporté de réponse).
Tu devrais mettre un print pour afficher le chemin complet avec os.path.realpath et voir s'il est ok
0