Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
771 connectés 

  FORUM HardWare.fr
  Programmation
  Python

  Tkinter et déplacement avec pression au clavier

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Tkinter et déplacement avec pression au clavier

n°1206836
Yoha2
Un bug peut en cacher un autre
Posté le 25-09-2005 à 11:45:35  profilanswer
 

A la base, j'avais ça:
 

Citation :

from graph import *
def move(h, v):
 global x, y
 x, y = x+h, x+v
 if x > 270:
  x = 0
 if x < 0:
  x = 270
 if y > 270:
  y = 0
 if y < 0:
  y = 270
 can.coords(rond, x, y, x+30, y+30)
 
x, y = 0, 0
fen= Tk()
fen.title("Le petit bonhomme" )
can=Canvas(fen, bg="grey", height=300, width=300)
rond=can.create_oval(x, y, x+30, y+30, width=2, fill="blue" )
can.bind("z", move(-10, 0))
can.bind("q", move(0, -10))
can.bind("d", move(0, 10))
can.bind("s", move(10, 0))
can.grid(row=0, column=0)
fen.mainloop()


 
je l'ai modifié en ça:
 

Citation :

from graph import *
def movez(event):
 move(-10, 0)
 
def moveq(event):
 move(0, -10)
 
def moved(event):
 move(0, 10)
 
def moves(event):
 move(10, 0)
 
def move(h, v):
 global x, y
 x, y = x+h, x+v
 if x > 270:
  x = 0
 if x < 0:
  x = 270
 if y > 270:
  y = 0
 if y < 0:
  y = 270
 can.coords(rond, x, y, x+30, y+30)
 
x, y = 0, 0
fen= Tk()
fen.title("Le petit bonhomme" )
can=Canvas(fen, bg="grey", height=300, width=300)
rond=can.create_oval(x, y, x+30, y+30, width=2, fill="blue" )
can.bind("z", movez)
can.bind("q", moveq)
can.bind("d", moved)
can.bind("s", moves)
can.grid(row=0, column=0)
fen.mainloop()


 
et ça marche toujours pas. Au fait, si vous trouvez ou ça va pas, vous pourriez m'aider à le faire avec les touches directionnelles ?
 
MErci d'avance.

mood
Publicité
Posté le 25-09-2005 à 11:45:35  profilanswer
 

n°1206877
masklinn
í dag viðrar vel til loftárása
Posté le 25-09-2005 à 12:27:12  profilanswer
 

[:petrus75]

Citation :

The form of the bind method is:  
 

def bind(self, sequence, func, add=''):


 
where:  
 
sequence  
is a string that denotes the target kind of event. (See the bind man page and page 201 of John Ousterhout's book for details).  
 
func  
is a Python function, taking one argument, to be invoked when the event occurs. An Event instance will be passed as the argument. (Functions deployed this way are commonly known as callbacks.)  
 
add  
is optional, either "" or "+". Passing an empty string denotes that this binding is to replace any other bindings that this event is associated with. Preceeding with a "+" means that this function is to be added to the list of functions bound to this event type.  
For example:  
 

   def turnRed(self, event):
        event.widget["activeforeground"] = "red"
 
    self.button.bind("<Enter>", self.turnRed)




---------------
Stick a parrot in a Call of Duty lobby, and you're gonna get a racist parrot. — Cody
n°1206919
Yoha2
Un bug peut en cacher un autre
Posté le 25-09-2005 à 14:32:35  profilanswer
 

Are you really english ?

n°1206929
masklinn
í dag viðrar vel til loftárása
Posté le 25-09-2005 à 14:52:03  profilanswer
 

hum, non, là j'ai simplement recopié la documentation tkinter située dans la doc python histoire de te montrer que tu n'utilises pas trop tk comme tu es censé le faire...
 
je te suggérerais donc, en concéquence, d'apprendre comment fonctionnent tkinter et python avant de demander pourquoi ce que tu fais ne fonctionne pas.
 
Et accessoirement t'as également oublié de demander l'affichage de ton canvas dans la frame principale, en utilisant grid ou pack.


Message édité par masklinn le 25-09-2005 à 15:02:08

---------------
Stick a parrot in a Call of Duty lobby, and you're gonna get a racist parrot. — Cody
n°1209695
Yoha2
Un bug peut en cacher un autre
Posté le 28-09-2005 à 12:15:46  profilanswer
 

Non, regarde à la fin

n°1209700
Yoha2
Un bug peut en cacher un autre
Posté le 28-09-2005 à 12:16:40  profilanswer
 

Il faut faire les "nid" après ?

n°1209701
Yoha2
Un bug peut en cacher un autre
Posté le 28-09-2005 à 12:17:12  profilanswer
 

les "bind" ?

n°1209703
masklinn
í dag viðrar vel til loftárása
Posté le 28-09-2005 à 12:18:48  profilanswer
 

[:petrus dei]


---------------
Stick a parrot in a Call of Duty lobby, and you're gonna get a racist parrot. — Cody
n°1209705
Yoha2
Un bug peut en cacher un autre
Posté le 28-09-2005 à 12:19:39  profilanswer
 

J'ai mis les "nid" avant "can.grid("

n°1209708
masklinn
í dag viðrar vel til loftárása
Posté le 28-09-2005 à 12:20:38  profilanswer
 

quels nids [:petrus dei]
 
mais de quoi tu parles [:petrus dei]


---------------
Stick a parrot in a Call of Duty lobby, and you're gonna get a racist parrot. — Cody
mood
Publicité
Posté le 28-09-2005 à 12:20:38  profilanswer
 

n°1209711
Yoha2
Un bug peut en cacher un autre
Posté le 28-09-2005 à 12:22:25  profilanswer
 

non, les "bind", faute de frappe, dsl

n°1212412
Yoha2
Un bug peut en cacher un autre
Posté le 01-10-2005 à 14:10:26  profilanswer
 

je voulais dire les 'can.bind("z", fonction)' par exemple.

n°1212836
Yoha2
Un bug peut en cacher un autre
Posté le 02-10-2005 à 13:57:03  profilanswer
 

Personne ?

n°1214670
Yoha2
Un bug peut en cacher un autre
Posté le 04-10-2005 à 15:57:52  profilanswer
 

Alors, une idée ?

n°1214716
Yoha2
Un bug peut en cacher un autre
Posté le 04-10-2005 à 16:46:40  profilanswer
 

ouinnn

n°1215089
dividee
Posté le 05-10-2005 à 00:32:23  profilanswer
 

Je crois que le problème c'est que ton canvas n'a pas le focus. Essaie soit d'ajouter can.focus_set() ou alors utilise bind_all au lieu de bind.
Pour les touches fléchées et autres, tout est ici: http://infohost.nmt.edu/tcc/help/pubs/tkinter/

n°1215373
Yoha2
Un bug peut en cacher un autre
Posté le 05-10-2005 à 12:29:15  profilanswer
 

Merci beaucoup. Ca marche mais les direction sont complétemetnt buggées...

n°1216128
Yoha2
Un bug peut en cacher un autre
Posté le 06-10-2005 à 08:27:01  profilanswer
 

Haut et bas ne marchent qu'une fois ou alors il faut partir vers le bas pour pouvoir remonter vers le heut et vice-versa... Droite et Gauche partent en diagonale...

n°1217022
dividee
Posté le 06-10-2005 à 20:19:02  profilanswer
 

Relis ton code:
x, y = x+h, x+v  :heink:

n°1218194
Yoha2
Un bug peut en cacher un autre
Posté le 08-10-2005 à 09:51:28  profilanswer
 

:lol:  :lol:  :lol:  :lol:  :lol:  :lol:  :lol:  :lol:  :lol:  
J'avais pas vu ça !!!!!!!!!!!!
Merci beaucoup, maintenant ça marche très bien.
 :lol:  :lol:  :lol:  :lol:  :lol:  :lol:  :lol:  :lol:  :lol:


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Python

  Tkinter et déplacement avec pression au clavier

 

Sujets relatifs
[Résolu]Batch et raccourci clavier[JAVA] Problème de déplacement de fichiers
touche spécial clavierTraiter les évènements du clavier et de la souris hors Swing
[Resolu]macro suite a une saisie clavierTkinter et threading
[Python & wxPython] Un Canvas comme dans Tkinterclavier d'imac
Saisie au clavier dans le paneau écran d'appletsaisie de chaine au clavier sans affichage de celle ci??
Plus de sujets relatifs à : Tkinter et déplacement avec pression au clavier


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR