IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tkinter Python Discussion :

Aide : Jeu feuille, cailloux, ciseau.


Sujet :

Tkinter Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut Aide : Jeu feuille, cailloux, ciseau.
    Voila sa parait stupide mais j'ai un petit probleme dans mon programme il ne veut pas afficher ma "chaine", si vous m'avez pas compris testez le =)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    from random import randrange 
    from Tkinter import *
     #variable
     
    feuille = 0
    cailloux = 0
    ciseau = 0
     
    feuilleb =0
    caillouxb = 0
    ciseaub = 0
    BOT = 0
     
    pointJ = 0
    pointB = 0
     
     #definiton des fonctions
     
    def choix(element) :
     
    	global feuille, cailloux, ciseau, feuilleb, caillouxb, cieaub, pointJ, pointB, BOT
    ####################
    ##BOT
    	BOT = randrange(1,3)
    	if BOT == 1 :
    		feuilleb += 1
    	elif BOT == 2 :
    		caillouxb += 1
    	elif BOT == 3 :
    		ciseaub += 1
     
    ####################
     
    	if element == 1 : #feuille
    		 feuille += 1
    		 if feuille ==1 and feuilleb ==1 :
    		 	chaine.configure(fenetre, text ='egaliter !')
    		 elif feuille ==1 and caillouxb == 1 :
    			chaine.configure(fenetre, text ='Vous gangez un point =P')
    			pointJ += 1
    		 elif feuille ==1 and ciseaub ==1 :
    			chaine.configure(fenetre, text ='Vous perdez =(')
    			pointB += 1
     
    #####################
     
    	elif element == 2 : #cailloux
    		cailloux += 1
    		if cailloux ==1 and caillouxb ==1 :
    			chaine.configure(fenetre, text ='egaliter !')
    		elif cailloux ==1 and feuilleb ==1 :
    			chaine.configure(fenetre, text ='Vous perdez =(')
    			pointB += 1
    		elif cailloux ==1 and ciseaub ==1 :
    			chaine.configure(fenetre, text ='Vous gagnez un point =P')
    			pointJ += 1
     
    #####################
     
    	elif element == 3 : #ciseau
    		ciseau += 1
    		if ciseau ==1 and ciseaub ==1 :
    			chaine.configure(fenetre, text ='egaliter !')
    		elif ciseau ==1 and feuilleb ==1 :
    			chaine.configure(fenetre, text ='Vous gagnez un point =P')
    			pointJ += 1
    		elif ciseau ==1 and caillouxb ==1 :
    			chaine.configure(fenetre, text ='Vous perdez =(')
    			pointB += 1
    # programe IG affichage
     
    fenetre = Tk()
    texte1 = Label(fenetre, text='Feuille, cailloux, ciseau, 1 2 3 !')
    texte1.pack()
    bouton1 = Button(fenetre, text="Feuille", command = (lambda: choix(1)))
    bouton1.pack()
    bouton2 = Button(fenetre, text="Cailloux", command = (lambda: choix(2)))
    bouton2.pack()
    bouton3 = Button(fenetre, text="Ciseau", command = (lambda: choix(3)))
    bouton3.pack()
    bouton4 = Button(fenetre, text="Quitter", command = fenetre.destroy)
    bouton4.pack()
    chaine = Label(fenetre)
    chaine.pack()
    Est lorce que je clik sur un des boutons l'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    chaine.configure(fenetre, text ='Vous gangez un point =P')
      File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1197, in configure
        return self._configure('configure', cnf, kw)
      File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1188, in _configure
        self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
    TclError: unknown option "-colormap"

  2. #2
    Membre expérimenté Avatar de Gaillac
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    165
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Avril 2008
    Messages : 165
    Par défaut
    Pour ton premier problème, avant que tu n'édite:

    feuille = 0
    cailloux = 0
    ciseau = 0


    et tu ne les change jamais ses valeurs.
    Et comme après tu ne modifie ton texte que si elles valent 1, tu n'es pas prêt d'afficher quelque chose...

    Pour ron second problème:

    remplace tout tes
    chaine.configure(fenetre, text ='blabla')
    par des
    chaine.configure(text ='blabla')

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut
    Merci beaucoup c'était sa =)
    juste maintenant encore un petit problème, mais je regarde si je trouve seul au pire je recrirais ;-)

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut
    Bon j'ai reussi a trouver l'erreur mais j'en ai deux nouvelles T.T
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    from random import randrange 
    from Tkinter import *
     #variable
     
    feuille = 0
    cailloux = 0
    ciseau = 0
     
    feuilleb =0
    caillouxb = 0
    ciseaub = 0
    BOT = 0
     
    pointJ = 0
    pointB = 0
     
     #definiton des fonctions
     
    def choix(element) :
    	global feuille, cailloux, ciseau, feuilleb, caillouxb, ciseaub, BOT, pointB, pointJ
    ####################
    ##BOT
    	BOT = randrange(1,3)
    	if BOT == 1 :
    		feuilleb += 1
    	elif BOT == 2 :
    		caillouxb += 1
    	elif BOT == 3 :
    		ciseaub += 1
     
    ####################
     
    	if element == 1 : #feuille
    		 feuille += 1
    		 if feuille ==1 and feuilleb ==1 :
    		 	chaine.configure(text ='egaliter !')
    		 elif feuille ==1 and caillouxb == 1 :
    			chaine.configure(text ='Vous gangez un point =P')
    			pointJ += 1
    		 elif feuille ==1 and ciseaub ==1 :
    			chaine.configure(text ='Vous perdez =(')
    			pointB += 1
     
    #####################
     
    	elif element == 2 : #cailloux
    		cailloux += 1
    		if cailloux ==1 and caillouxb ==1 :
    			chaine.configure(text ='egaliter !')
    		elif cailloux ==1 and feuilleb ==1 :
    			chaine.configure(text ='Vous perdez =(')
    			pointB += 1
    		elif cailloux ==1 and ciseaub ==1 :
    			chaine.configure(text ='Vous gagnez un point =P')
    			pointJ += 1
     
    #####################
     
    	elif element == 3 : #ciseau
    		ciseau += 1
    		if ciseau ==1 and ciseaub ==1 :
    			chaine.configure(text ='egaliter !')
    		elif ciseau ==1 and feuilleb ==1 :
    			chaine.configure(text ='Vous gagnez un point =P')
    			pointJ += 1
    		elif ciseau ==1 and caillouxb ==1 :
    			chaine.configure(text ='Vous perdez =(')
    			pointB += 1
    ##################
    	#chaine2.configure(text = "Vos points :" + str(pointJ))
    	#chaine3.configure(text = "point du Bot :" + str(pointB))
     
    # programe IG affichage
     
    fenetre = Tk()
    texte1 = Label(fenetre, text='Feuille, cailloux, ciseau, 1 2 3 !')
    texte1.pack()
    bouton1 = Button(fenetre, text="Feuille", command = (lambda: choix(1)))
    bouton1.pack()
    bouton2 = Button(fenetre, text="Cailloux", command = (lambda: choix(2)))
    bouton2.pack()
    bouton3 = Button(fenetre, text="Ciseau", command = (lambda: choix(3)))
    bouton3.pack()
    bouton4 = Button(fenetre, text="Quitter", command = fenetre.destroy)
    bouton4.pack()
    chaine = Label(fenetre)
    chaine.pack()
    chaine2 = Label(fenetre, text='Vos points :'+ str(pointJ))
    chaine2.pack(side=BOTTOM)
    chaine3 = Label(fenetre, text='Les points du Bot :'+ str(pointB))
    chaine3.pack(side=BOTTOM)
    1er erreur : Les points ne fonctionnent pas il reste toujours a 0
    2eme erreur : le Bot se met a foirer au bout de 2, 3 coups.
    PS : (aucune erreur dans la console)

  5. #5
    Candidat au Club
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2008
    Messages
    4
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2008
    Messages : 4
    Par défaut
    En fait si tu fais un print en console tu vas te rendre compte que les points se mettent à jour (enfin, je pense, je l'ai pas exécuté pour tester). Seulement tu ne mets jamais le texte de ton interface à jour.

    Pour le second problème, tu ne remets jamais la valeur de tes variables à zéro. Tu peux donc te retrouver avec feuille = 10...

    Sinon je pense qu'une bonne refactorisation du code pourrait être intéressante ^_^

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2008
    Messages : 85
    Par défaut
    Citation Envoyé par kujiu Voir le message
    En fait si tu fais un print en console tu vas te rendre compte que les points se mettent à jour (enfin, je pense, je l'ai pas exécuté pour tester). Seulement tu ne mets jamais le texte de ton interface à jour.

    Pour le second problème, tu ne remets jamais la valeur de tes variables à zéro. Tu peux donc te retrouver avec feuille = 10...

    Sinon je pense qu'une bonne refactorisation du code pourrait être intéressante ^_^
    Merci !
    mais qu'es qu'une refactorisation ? =)

    EDIT : je viens de voir ton Edit je test en remettant les valeurs a 0 !

Discussions similaires

  1. aide jeu en java
    Par pompom8 dans le forum Développement 2D, 3D et Jeux
    Réponses: 0
    Dernier message: 26/02/2010, 16h39
  2. Image, fichier d'aide et feuille MDI
    Par bruce207 dans le forum VB 6 et antérieur
    Réponses: 15
    Dernier message: 15/05/2008, 18h29
  3. Besoin d'aide jeu du morpion
    Par narcis60floyjo dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 28/02/2008, 15h14
  4. Championnat du monde de feuille caillou ciseau
    Par Invité dans le forum La taverne du Club : Humour et divers
    Réponses: 7
    Dernier message: 18/12/2007, 10h53
  5. BESOIN AIDE JEU BASKET
    Par stitch666 dans le forum Flash
    Réponses: 4
    Dernier message: 19/09/2007, 17h14

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo