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 :

Débutant - Erreur : Liés des touches (clavier) à une fonction.


Sujet :

Tkinter Python

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2018
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2018
    Messages : 4
    Par défaut Débutant - Erreur : Liés des touches (clavier) à une fonction.
    Bonjour, je suis débutant dans la programmation, notamment en Python, je suis en train de crée un petit jeu qui aurait pour but de faire se déplacer une balle dans un labyrinthe, et d'en rejoindre la sortie, pour pimenter le jeu, lorsque l'on commencerais a bouger la balle, les murs disparaitrait et il faudrait donc laisser place à la mémoire pour rejoindre (sans voir les mur) la sortie. Ayant déjà bien avancer dans la création des menu, je me suis lancer dans la création d'un premier niveau, je commence donc par vouloir faire bouger la balle grâce aux touches directionnels du clavier, malheureusement, je n'y parvient pas. Je vous joint donc intégralité de mon projet, au cas ou il y aurait une erreur quelque part. (les partie qui nous intéresse sont aux début "#Fonctions de déplacements:" et tout à la fin, la fonction "niveau1_bouton", je vous remercie pour toute aide venant de votre part.

    *Partie interessante en gras
    *Je joint également une version txt. de mon projet.

    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
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    from tkinter import*
    import tkinter.font as tkFont
    
    
        #Fenetre du jeu:
    
    fen = Tk()
    fen.title('Black Wall')
    
    
    
        #Definition d'images:
    
    fondmenu = PhotoImage (file='Textures/MainMenuAdds/fondmenu.png')
    fondpause = PhotoImage (file='Textures/PauseAdds/fondpause.png')
    fondniveau1 = PhotoImage (file='Textures/LevelAdds/fondniveau1.png')
    titre_menu = PhotoImage (file='Textures/MainMenuAdds/French/titre.png')
    titre_niveau = PhotoImage (file='Textures/LevelAdds/French/titre_niveau.png')
    titre_pause = PhotoImage (file='Textures/PauseAdds/titre_pause.png')
    coin_img = PhotoImage (file='Textures/Stuffs/coin.png')
    
    
    
            #Definition d'images pour les boutons:
    
    jouer_button = PhotoImage (file='Textures/FrenchMainButton/jouer.png')
    niveau_button = PhotoImage (file='Textures/FrenchMainButton/niveau.png')
    option_button = PhotoImage (file='Textures/FrenchMainButton/option.png')
    custom_button = PhotoImage (file='Textures/FrenchMainButton/custom.png')
    quitter_button = PhotoImage (file='Textures/FrenchMainButton/quitter.png')
    aide_button = PhotoImage (file='Textures/FrenchMainButton/aide.png')
    backmenu_button = PhotoImage (file='Textures/FrenchMainButton/backmenu.png')
    pause_button = PhotoImage (file='Textures/PauseAdds/pause.png')
    reprendre_button = PhotoImage (file='Textures/PauseAdds/reprendre.png')
                #Boutton du Menu_Niveau:
    niveau1_button = PhotoImage (file='Textures/FrenchLevelsButton/niveau1.png')
    niveau2_button = PhotoImage (file='Textures/FrenchLevelsButton/niveau2.png')
    niveau3_button = PhotoImage (file='Textures/FrenchLevelsButton/niveau3.png')
    niveau4_button = PhotoImage (file='Textures/FrenchLevelsButton/niveau4.png')
    niveau5_button = PhotoImage (file='Textures/FrenchLevelsButton/niveau5.png')
    niveau6_button = PhotoImage (file='Textures/FrenchLevelsButton/niveau6.png')
    niveau7_button = PhotoImage (file='Textures/FrenchLevelsButton/niveau7.png')
    niveau8_button = PhotoImage (file='Textures/FrenchLevelsButton/niveau8.png')
    niveau9_button = PhotoImage (file='Textures/FrenchLevelsButton/niveau9.png')
    niveau10_button = PhotoImage (file='Textures/FrenchLevelsButton/niveau10.png')
    niveau11_button = PhotoImage (file='Textures/FrenchLevelsButton/niveau11.png')
    niveau12_button = PhotoImage (file='Textures/FrenchLevelsButton/niveau12.png')
    
    
    
    
        #Definition de variables:
    
            #C => Nombres de pièces:
    C = 0
            #Coordonees de la Balle au départ:
    x1, y1 = 100, 100
            #Tout les menu(CANVAS):
    MENU_A = Canvas(fen)
    MENU_P = Canvas(fen)
    MENU_N = Canvas(fen)
    MENU_O = Canvas(fen)
    MENU_C = Canvas(fen)
    NIVEAU1 = Canvas(fen)
    NIVEAU2 = Canvas(fen)
    NIVEAU3 = Canvas(fen)
    NIVEAU4 = Canvas(fen)
    NIVEAU5 = Canvas(fen)
    NIVEAU6 = Canvas(fen)
    NIVEAU7 = Canvas(fen)
    NIVEAU8 = Canvas(fen)
    NIVEAU9 = Canvas(fen)
    NIVEAU10 = Canvas(fen)
    NIVEAU11 = Canvas(fen)
    NIVEAU12 = Canvas(fen)
    PAUSE = Canvas(fen)
          #Création de la balle:
    
    
        #Definition de font:
    
    font_coin = tkFont.Font (family="Tahoma", size=15, weight='bold')
    
    ########################################################################
    
    #Fonctions de déplacements:
    
    def avance(gd, hb):
            global x1, y1
            x1, y1 = x1+gd, y1+hb
            fen.coords(balle, x1,y1, x1+30,y1+30)
    
    def dplgauche(event):
            NIVEAU1.move(balle, -10, 0)
    
    def dpldroite(event):
            NIVEAU1.move(balle, 10, 0)
    
    def dplhaut(event):
            NIVEAU1.move(balle, 0, -10)
    
    def dplbas(event):
            NIVEAU1.move(balle, 0, 10)
    
    #Menu_Niveau:
    
    def niveau_bouton():
        MENU_N = Canvas(fen, bg ="grey", width =900, height =600)
        MENU_N.grid(row =2, column =0, columnspan =2)
            #Fond du Menu_Niveau:
        MENU_N.create_image(0, 0, image=fondmenu, anchor=NW)
            #Titre du Menu_Niveau:
        MENU_N.create_image(475, 60, image =titre_niveau, anchor="center")
            #Boutons Menu_Niveau:
        backmenu = Button(MENU_N)
        backmenu.config(image =backmenu_button, width =270, height =35, bg ="grey", relief ="flat", cursor ="hand1", command =backmenu_bouton)
        backmenu.place(x =450, y =550, anchor ="center")
            #Boutons des niveau:
        niveau1 = Button(MENU_N)
        niveau1.config(image =niveau1_button, width =150, height =35, bg ="grey", relief ="flat", cursor ="hand1", command=niveau1_bouton)
        niveau1.place(x =150, y =150, anchor ="center")
        niveau2 = Button(MENU_N)
        niveau2.config(image =niveau2_button, width =150, height =35, bg ="grey", relief ="flat", cursor ="hand1")
        niveau2.place(x =450, y =150, anchor ="center")
        niveau3 = Button(MENU_N)
        niveau3.config(image =niveau3_button, width =150, height =35, bg ="grey", relief ="flat", cursor ="hand1")
        niveau3.place(x =750, y =150, anchor ="center")
        niveau4 = Button(MENU_N)
        niveau4.config(image =niveau4_button, width =150, height =35, bg ="grey", relief ="flat", cursor ="hand1")
        niveau4.place(x =150, y =250, anchor ="center")
        niveau5 = Button(MENU_N)
        niveau5.config(image =niveau5_button, width =150, height =35, bg ="grey", relief ="flat", cursor ="hand1")
        niveau5.place(x =450, y =250, anchor ="center")
        niveau6 = Button(MENU_N)
        niveau6.config(image =niveau6_button, width =150, height =35, bg ="grey", relief ="flat", cursor ="hand1")
        niveau6.place(x =750, y =250, anchor ="center")
        niveau7 = Button(MENU_N)
        niveau7.config(image =niveau7_button, width =150, height =35, bg ="grey", relief ="flat", cursor ="hand1")
        niveau7.place(x =150, y =350, anchor ="center")
        niveau8 = Button(MENU_N)
        niveau8.config(image =niveau8_button, width =150, height =35, bg ="grey", relief ="flat", cursor ="hand1")
        niveau8.place(x =450, y =350, anchor ="center")
        niveau9 = Button(MENU_N)
        niveau9.config(image =niveau9_button, width =150, height =35, bg ="grey", relief ="flat", cursor ="hand1")
        niveau9.place(x =750, y =350, anchor ="center")
        niveau10 = Button(MENU_N)
        niveau10.config(image =niveau10_button, width =150, height =35, bg ="grey", relief ="flat", cursor ="hand1")
        niveau10.place(x =150, y =450, anchor ="center")
        niveau11 = Button(MENU_N)
        niveau11.config(image =niveau11_button, width =150, height =35, bg ="grey", relief ="flat", cursor ="hand1")
        niveau11.place(x =450, y =450, anchor ="center")
        niveau12 = Button(MENU_N)
        niveau12.config(image =niveau12_button, width =150, height =35, bg ="grey", relief ="flat", cursor ="hand1")
        niveau12.place(x =750, y =450, anchor ="center")
    
    #Menu_Option
    
    def option_bouton():
        MENU_O = Canvas(fen, bg ="grey", width =900, height =600)
        MENU_O.grid(row =2, column =0, columnspan =2)
        MENU_O.create_image(0, 0, image=fondmenu, anchor=NW)
            #Boutons Menu_Option:
        backmenu = Button(MENU_O)
        backmenu.config(image =backmenu_button, width =270, height =35, bg ="grey", relief ="flat", cursor ="hand1", command =backmenu_bouton)
        backmenu.place(x =450, y =550, anchor ="center")
    
    #Menu_Custom
    
    def custom_bouton():
        MENU_C = Canvas(fen, bg ="grey", width =900, height =600)
        MENU_C.grid(row =2, column =0, columnspan =2)
        MENU_C.create_image(0, 0, image=fondmenu, anchor=NW)
            #Boutons Menu_Custom:
        backmenu = Button(MENU_C)
        backmenu.config(image =backmenu_button, width =270, height =35, bg ="grey", relief ="flat", cursor ="hand1", command =backmenu_bouton)
        backmenu.place(x =450, y =550, anchor ="center")
    
    #Menu_Aide:
    
    def aide_bouton():
        MENU_A = Canvas(fen, bg ="grey", width =900, height =600)
        MENU_A.grid(row =2, column =0, columnspan =2)
        MENU_A.create_image(0, 0, image=fondmenu, anchor=NW)
            #Boutons Menu_Aide:
        backmenu = Button(MENU_A)
        backmenu.config(image =backmenu_button, width =270, height =35, bg ="grey", relief ="flat", cursor ="hand1", command =backmenu_bouton)
        backmenu.place(x =450, y =550, anchor ="center")
    
    #Menu_Principale:
    
    def backmenu_bouton():
    
        MENU_P = Canvas(fen, bg ="grey", width =900, height =600)
        MENU_P.grid(row =2, column =0, columnspan =2)
            #Fond du Menu_Principale:
        MENU_P.create_image(0, 0, image=fondmenu, anchor=NW)
            #Titre du Menu_Principale:
        MENU_P.create_image(450, 125, image=titre_menu, anchor="center")
            #Image_COIN Menu_Principale:
        MENU_P.create_image(725, 560, image=coin_img, anchor=NW)
    
            #Textes Menu_Principale:
    
        coin_txt = MENU_P.create_text(800, 577, text="COIN :", font=font_coin, fill="white")
        version_txt = MENU_P.create_text(39, 591, text="version 1.1", font="Corbel", fill="white")
        nb_coin_txt = MENU_P.create_text(860, 577, text=C, font=font_coin, fill="white")
    
    
            #Boutons Menu_Principale:
    
        jouer = Button(MENU_P)
        jouer.config(image =jouer_button, width =250, height =75, bg="grey", relief ="flat", cursor ="hand1", command=niveau1_bouton)
        jouer.place(x =450, y =250, anchor ="center")
        niveau = Button(MENU_P)
        niveau.config(image =niveau_button, width =140, height =35, bg ="grey", relief ="flat", cursor ="hand1", command=niveau_bouton)
        niveau.place(x =450, y =325, anchor ="center")
        option = Button(MENU_P)
        option.config(image =option_button, width =140, height =35, bg ="grey", relief ="flat", cursor ="hand1", command=option_bouton)
        option.place(x =450, y =375, anchor ="center")
        custom = Button(MENU_P)
        custom.config(image =custom_button, width =140, height =35, bg ="grey", relief ="flat", cursor ="hand1", command=custom_bouton)
        custom.place(x =450, y =425, anchor ="center")
        aide = Button(MENU_P)
        aide.config(image =aide_button, width =140, height =35, bg ="grey", relief ="flat", cursor ="hand1", command=aide_bouton)
        aide.place(x =450, y =475, anchor ="center")
        quitter = Button(MENU_P)
        quitter.config(image =quitter_button, width =140, height =35, bg ="grey", relief ="flat", cursor ="hand1", command=quitter_bouton)
        quitter.place(x =450, y =525, anchor ="center")
    
    #Menu_Quitter:
    
    def quitter_bouton():
        fen.quit
    
    #Menu_Pause:
    
    def pause_bouton():
        PAUSE = Canvas(fen, bg ="dark grey", width =600, height =400)
        PAUSE.grid(row =2, column =0, columnspan =2)
             #Fond du Menu_Pause:
        PAUSE.create_image(0, 0, image=fondpause, anchor=NW)
            #Titre du Menu_Pause:
        PAUSE.create_image(300, 70, image =titre_pause, anchor="center")
            #Boutons du Menu_Pause:
        backmenu = Button(PAUSE)
        backmenu.config(image =backmenu_button, width =270, height =35, bg ="dark grey", relief ="flat", cursor ="hand1", command =backmenu_bouton)
        backmenu.place(x =300, y =170, anchor ="center")
        niveau = Button(PAUSE)
        niveau.config(image =niveau_button, width =140, height =35, bg ="dark grey", relief ="flat", cursor ="hand1", command=niveau_bouton)
        niveau.place(x =300, y =270, anchor ="center")
        reprendre = Button(PAUSE)
        reprendre.config(image =reprendre_button, width =200, height =35, bg ="dark grey", relief ="flat", cursor ="hand1", command=PAUSE.destroy)
        reprendre.place(x =300, y =220, anchor ="center")
    
    
    #Menu_Niveau1:
    
    def niveau1_bouton():
        global x1, y1, balle, dplhaut, dplbas, dplgauche, dpldroite
        NIVEAU1 = Canvas(fen, bg ="grey", width =900, height =600)
        NIVEAU1.grid(row =2, column =0, columnspan =2)
            #Fond du Niveau1:
        NIVEAU1.create_image(0, 0, image=fondniveau1, anchor=NW)
            #Boutons du Niveau1:
        pause = Button(fen)
        pause.config(image =pause_button, width =40, height =40, bg ="grey", relief ="flat", cursor ="hand1", command=pause_bouton)
        pause.place(x =870, y =30, anchor ="center")
            #Map du Niveau1:
        balle = NIVEAU1.create_oval(x1, y1, x1+30, y1+30, width=1, fill="white")
            #Definition des touches :
        NIVEAU1.bind('<Up>', dplhaut) # Flèche haut
        NIVEAU1.bind('<Down>', dplbas) # Flèche bas
        NIVEAU1.bind('<Left>', dplgauche) # Flèche gauche
        NIVEAU1.bind('<Right>', dpldroite) # Flèche droite
    
    
    
    
    
    
    
    
    
    backmenu_bouton()
    
    fen.mainloop()
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. [AS2] déclarer des variables dans une fonction
    Par ooyeah dans le forum ActionScript 1 & ActionScript 2
    Réponses: 12
    Dernier message: 02/08/2005, 12h50
  2. Réponses: 7
    Dernier message: 20/03/2005, 14h53
  3. Erreur a l'appel d'une fonction javascript
    Par linou dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 10/03/2005, 11h16
  4. fonction récupérant des valeurs dans une fonction popup...
    Par petitsims dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 20/01/2005, 14h51
  5. [JEditorPane]Captures des touches claviers
    Par splend_f dans le forum Agents de placement/Fenêtres
    Réponses: 5
    Dernier message: 17/05/2004, 14h57

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