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

GUI Python Discussion :

Problème de Binding dans une boucle [Python 3.X]


Sujet :

GUI Python

  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2015
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2015
    Messages : 2
    Points : 3
    Points
    3
    Par défaut Problème de Binding dans une boucle
    Bonsoir,
    J'ai un petit problème concernant l'instruction ***.bind() de tkinter sous python 3. Mon problème est que j'ai lié mon canevas à mon clic gauche lors d'une boucle, et ça ne fonctionne qu'une fois. En clair, mon programme s'exécute correctement la première fois ( il lie le canevas à mon clic gauche sans problème), mais la seconde fois que la boucle passe par l'instruction, on dirait qu'il ignore mon .bind(). Il s'arrête lors du premier bine pendant la deuxième fois qu'il fait son chemin.
    Est-ce que quelqu'un à déjà rencontrer ce genre de problème ?
    Merci de votre attention !
    Je copie la partie du programme qui ne marche pas:
    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
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    def continuerounon():
        global dico_cartes
        if len(dico_cartes) != 0:
            deplacement()
     
    def deplacement():
        global can,titre_paquet,ax,ay,bx,by,cx,cy,dx,dy,x1,x2,y1,y2,xx1,yy1,carte_question,dico_cartes
        ax = 1030
        ay = 568
        bx = 1430
        by = 568
        cx = 1430
        cy = 818
        dx = 1030
        dy = 818
        xx1 = 1230
        yy1 = 643
        while ax > 530:
            if ax%2 == 0:
                ax-=1
                ay-=1
                bx-=1
                by-=1
                cx-=1
                cy-=1
                dx-=1
                dy-=1
                total = ax,ay,bx,by,cx,cy,dx,dy
                xx1 -= 1
                yy1 -= 1
                can.coords(carte_question[0]-1, total)
                can.coords(carte_question[0], xx1,yy1)
                can.update()
                time.sleep(0.00000001)
            else:
                ax -= 1
                bx -= 1
                cx -= 1
                dx -= 1
                xx1 -= 1
                total = ax,ay,bx,by,cx,cy,dx,dy
                can.coords(carte_question[0]-1, total)
                can.coords(carte_question[0], xx1,yy1)
                can.update()
                time.sleep(0.00000001)
        can.update()
        can.bind("<Button-1>",retour)
    #---------------------------------------------------------------------------------------------------
    # Comment retourner une carte ?
    #---------------------------------------------------------------------------------------------------
    #- - - - - - - - - - - - - - -
    # Retournement de la carte
    #- - - - - - - - - - - - - - -
    def retour(info):
        global ax,ay,bx,by,cx,cy,dx,dy,couleur,can,carre,bleu,rouge,vert,texte,coul,noir,retour,tot,carte_question,dico_cartes,vu,croix,carte_texte
        print("Je suis à <retour>")
        del info
        tags = can.find_withtag(carte_question[0])
        carte = tags[0]
        texte = can.gettags(carte)
        texteaffichage = texte[1]
        for q,r in dico_cartes.items():
            if texteaffichage == q:
                textereponse = r
        while ax != 930:
            for autre in range(3):
                if retour != 'o':
                    can.delete(carte_question[0])
                    can.delete(texte)
                    if couleur != coul:
                        red()
                        green()
                        blue()
                        couleur = '#'+''.join(rouge)+''.join(vert)+''.join(bleu)
                        texte = can.create_text(730,393, text=texteaffichage, font=("HELVETICA",30), fill = couleur, tags = 'texte')
                    else:
                        retour = 'o'
                elif ax >= 830 and retour == 'o':
                    if couleur != noir:
                        retourred()
                        retourgreen()
                        retourblue()
                        can.delete(texte)
                        couleur = '#'+''.join(rouge)+''.join(vert)+''.join(bleu)
                        texte = can.create_text(730,393, text=textereponse, font=("HELVETICA",30), fill = couleur, tags = 'texte')
            if ax != 930:
                if ax % 10 == 0 and ax < 730:
                    ay += 1
                    dy -= 1
                    by -= 1
                    cy += 1
                if ax % 10 == 0 and ax >= 730:
                    ay -= 1
                    dy += 1
                    by += 1
                    cy -= 1
                cx -= 1
                bx -= 1
                ax += 1
                dx += 1
                position = ax,ay,bx,by,cx,cy,dx,dy
                can.coords(carte-1,position)
                can.update()
                time.sleep(0.0001)
        carte_texte.append(texte)
        can.create_image(570,530, image=vu,tags='vu')
        can.create_image(890,530, image=croix,tags='croix')
        can.update()
        can.bind("<Button-1>",action)   
     
    #- - - - - - - - - - - - - - -
    # Décision de la personne
    #- - - - - - - - - - - - - - -
    def juste():
        global ax,ay,bx,by,cx,cy,dx,dy,can, carte_question ,xx1,yy1, carte_texte
        print("Je suis à <juste>")
        can.delete(can.find_withtag("vu"))
        can.delete(can.find_withtag("croix"))
        print("Carte question 2 = ", carte_question)
        carte = carte_question[0]
        while ay > -250:
            ay -= 1
            by -= 1
            cy -= 1
            dy -= 1
            yy1 -= 1
            position = ax,ay,bx,by,cx,cy,dx,dy
            place = xx1,yy1
            can.coords(carte-1,position)
            can.coords(carte_texte[0],place)
            can.update()
            time.sleep(0.000001)
        carte_question.remove(carte_question[0])
        carte_texte.remove(carte_texte[0])
        print(carte_texte)
        can.after(500,continuerounon())
     
    def faux():
        global ax,ay,bx,by,cx,cy,dx,dy,can, carte_question ,xx1,yy1, carte_texte
        print("Je suis à <faux>")
        can.delete(can.find_withtag("vu"))
        can.delete(can.find_withtag("croix"))
        print("Carte question 2 = ", carte_question)
        carte = carte_question[0]
        while ay < 1500:
            ay += 1
            by += 1
            cy += 1
            dy += 1
            yy1 += 1
            position = ax,ay,bx,by,cx,cy,dx,dy
            place = xx1,yy1
            can.coords(carte-1,position)
            can.coords(carte_texte[0],place)
            can.update()
            time.sleep(0.000001)
        carte_question.remove(carte_question[0])
        carte_texte.remove(carte_texte[0])
        print(carte_texte)
        can.after(500,continuerounon())
     
    def action(event):
        global can
        print("Je suis à <action>")
        boutonSel = can.find_closest(event.x, event.y)
        if len(boutonSel) != 0:
            boutonID = boutonSel[0]
            nom = can.gettags(boutonID)
            if nom[0] == "retour":
                del event
                creation_accueil()
            elif nom[0] == "automat":
                del event
                crea_auto()
            elif nom[0] == "manuel":
                del event
                crea_manu()
            elif nom[0] == "poubelle":
                del event
                supprimer()
            elif nom[0] == "revision":
                del event
                revision_commencement()
            elif nom[0] == "vu":
                del event
                juste()
            elif nom[0] == "croix":
                del event
                faux()

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 285
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 285
    Points : 36 773
    Points
    36 773
    Par défaut
    Salut,

    Si .bind avait de tels soucis, ce serait un bug et "çà se saurait".
    Par contre, des appels à update dans les callbacks qui foutent la grouille, çà c'est connu...

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  3. #3
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2015
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2015
    Messages : 2
    Points : 3
    Points
    3
    Par défaut
    En fait, c'était un problème de variable qui avait le même nom que ma fonction.
    Merci de l'aide

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [SimpleXML] Google Maps, Problème d'encoding dans une boucle
    Par yahn dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 23/09/2006, 19h40
  2. Réponses: 2
    Dernier message: 28/08/2006, 13h16
  3. Problème de SCANF dans une boucle WHILE
    Par FidoDido® dans le forum C
    Réponses: 4
    Dernier message: 30/12/2005, 17h42
  4. [Conception] Problème de test dans une boucle while
    Par Cyrius dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 26/11/2005, 18h07
  5. Problème avec TNMSMTP dans une boucle.
    Par Orgied dans le forum Web & réseau
    Réponses: 3
    Dernier message: 07/04/2004, 10h19

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