Au secours, probleme python!!

Fermé
callmenelly Messages postés 4 Date d'inscription mercredi 8 mai 2013 Statut Membre Dernière intervention 9 mai 2013 - Modifié par callmenelly le 8/05/2013 à 20:53
callmenelly Messages postés 4 Date d'inscription mercredi 8 mai 2013 Statut Membre Dernière intervention 9 mai 2013 - 9 mai 2013 à 11:44
Bonjour!
Je suis désespérément à la recherche de quelqu'un qui pourrait m'aider. Cela fait des jours que je cherche une solution, en vain.
Je travaille sur un projet qui est en fait de créer un puzzle, mais impossible de déplacer une seule image ! Je voudrais que l'utilisateur puisse déplacer les pièces d'un puzzle. Voici mon code :



from Tkinter import * 
import tkFont 
from PIL import Image,ImageTk 
from PIL import * 

test='1350x750' 


def clic(event1): 
    
    global detectionclic 

    # position de la souris 
    X = event1.x 
    Y = event1.y 
    print "Position souris : ",X,Y 

    # coordonnées de la pièce du puzzle 
    [xmin,ymin,xmax,ymax] = CANEVAS1.coords(C) 

    print "Position objet : ",xmin,ymin,xmax,ymax 
    if xmin<=X<=xmax and ymin<=Y<=ymax: detectionclic = True 
    else: detectionclic = False 
    print "Detection clic : ",detectionclic 

def deplace(event2): 
    
    X = event2.x 
    Y = event2.y 
    print "Position souris : ",X,Y 

    if detectionclic == True: 
        # limite de l'objet dans la zone graphique 
        if X<0: X=0 
        if X>1350: X=1350 
        if Y<0: Y=0 
        if Y>730: Y=730 
        # mise à jour de la position de l'objet (deplace) 
        CANEVAS1.coords(C,X-100,Y-100,X+100,Y+100) 


detectionclic = False 


t3=Tk() 
t3.geometry(test) 

global CANEVAS1 

CANEVAS1 = Canvas(t3,bg='light yellow',height=750,width=1350) 

can2=Canvas(CANEVAS1,bg='blue',height=200,width=800) 
image = Image.open('C:\\4pieces1.jpg') 
photo1 = ImageTk.PhotoImage(image) 
C = can2.create_image(102,102, image=photo1) 
can2.grid(row=1,column=1,pady=150) 

bout2=Button(CANEVAS1,text='Abandon',command=t3.destroy, font = ('arial', '16')) 
bout2.grid(row=2,column=1,pady=50,padx=630) 

CANEVAS1.bind('<Button-1>',clic) 
CANEVAS1.bind('<B1-Motion>',deplace) 

CANEVAS1.focus_set() 
CANEVAS1.grid(row=0,column=0,rowspan=10,columnspan=10) 

t3.mainloop() 







Et je reçoit l'erreur suivante :
Exception in Tkinter callback 
Traceback (most recent call last): 
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__ 
    return self.func(*args) 
  File "C:\Users\Callmenelly\Desktop\Frame.py", line 20, in clic 
    [xmin,ymin,xmax,ymax] = CANEVAS1.coords(C) 
ValueError: need more than 0 values to unpack




Je suis débutante en programmation. J'ai besoin d'aide .. merci d'avance!
A voir également:

2 réponses

callmenelly Messages postés 4 Date d'inscription mercredi 8 mai 2013 Statut Membre Dernière intervention 9 mai 2013 1
8 mai 2013 à 21:11
ça s'appelle le 'drag and drop' .

que veux dire mon erreur ?? Personne pour m'aider ? :(
0
callmenelly Messages postés 4 Date d'inscription mercredi 8 mai 2013 Statut Membre Dernière intervention 9 mai 2013 1
9 mai 2013 à 11:44
SVP, c'est urgent!
0