2014-06-21 68 views
0

我需要知道如何檢測用鼠標拖動的橢圓是否進入另一個形狀(矩形)。Python在另一個形狀上檢測形狀

class Bloque(): # Creates a block 
    def __init__(self, lista, ventana): 
     self.espacio = ventana # assings the canvas 
     box = self.espacio.create_rectangle(x1, y1, x2, y2, width = 0) # creates the block 
     self.espacio.tag_bind(box, '<Enter>', lambda e: print("Passed over")) 

這檢測鼠標是否通過該塊,但是當我在塊上拖動其他形狀時,它不會被檢測到。所以當我在塊上拖動其他形狀時,我怎麼能給我一個信息? 謝謝。

回答

0

此解決方案假定橢圓形ID存儲在self.oval。另請注意,我已將該框ID存儲在實例變量self.box中,而不是本地變量box

class Bloque(): # Creates a block 
    def __init__(self, lista, ventana): 
     self.espacio = ventana # assings the canvas 
     self.box = self.espacio.create_rectangle(x1, y1, x2, y2, width = 0) # creates the block 
     self.espacio.tag_bind(self.box, '<B1-Motion>', self.detectIntersection) 

    def detectIntersection(self, event): 
     overlaps = self.espacio.find_overlapping(*self.espacio.bbox(box)) 
     if self.oval in overlaps: 
      print("Passed over") 
相關問題