4
A
回答
5
這裏有一個小的演示(我不(T remmeber excatly是它來自於,對不起),這是非常相似的一個發現這裏:http://www.pygtk.org/pygtk2tutorial/examples/dragndrop.py
import gtk
class DragImage(gtk.Image):
def __init__(self,image,layout):
gtk.Image.__init__(self)
self.drag = False
self.drag_x = 0
self.drag_y = 0
self.layout = layout
self.x = 0
self.y = 0
self.set_from_file(image)
self.event_box = gtk.EventBox()
self.event_box.set_visible_window(False)
self.event_box.add(self)
self.event_box.add_events(gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK)
self.event_box.connect("button-press-event", self.click)
self.event_box.connect("button-release-event", self.release)
self.event_box.connect("motion-notify-event", self.mousemove)
self.layout.put(self.event_box, 0, 0)
def click(self, widget, event):
self.drag = True
self.drag_x = event.x
self.drag_y = event.y
print(self.drag_x, self.drag_y)
def release(self, widget, event):
self.drag = False
def mousemove(self,widget,event):
if self.drag:
self.layout.move(self.event_box,self.x+int(event.x-self.drag_x),self.y+int(event.y-self.drag_y))
self.x, self.y = self.layout.child_get(self.event_box,'x','y')
class move_test(object):
def __init__(self):
window = gtk.Window()
layout = gtk.Layout()
img1 = DragImage('image1.jpg',layout)
img2 = DragImage('image2.jpg',layout)
window.add(layout)
window.show_all()
move_test()
gtk.main()
相關問題
- 1. 如何拖動圖像
- 2. 拖動圖像?
- 3. 拖動圖像
- 4. 使用HTML5拖放操作時,如何在拖放區域上拖動圖像?
- 5. 如何使用JQuery拖動運動圖像?
- 6. pygtk圖像網格
- 7. 使用MouseDrag方法拖動圖像
- 8. Android拖動圖像
- 9. 圖像拖動導致按鈕拖動
- 10. 用可拖動的圖像更改可拖放的圖像源
- 11. 拖動圖像視圖
- 12. Java拖放圖像並拖動時顯示圖像縮略圖
- 13. 如何在Android應用程序中使用觸摸拖動圖像視圖
- 14. pygtk的圖像淡入
- 15. Android拖放 - 圖像沒有被拖動
- 16. Android的拖放(不能拖動圖像)
- 17. 從滾動視圖中拖動圖像
- 18. 插入圖像拖動
- 19. 在flex中拖動圖像
- 20. 在UIScrollView上拖動圖像
- 21. IOS:拖動多個圖像
- 22. 拖動邊界圖像
- 23. 在XNA中拖動圖像
- 24. 在WPF中拖動圖像
- 25. 兩個圖像拖動
- 26. 從uitableview拖動圖像
- 27. 圖像拖動父遏制
- 28. 小工具拖動圖像
- 29. 拖動圖像設備
- 30. Pygame拖動背景圖像
看到[的文檔]第22章(HTTP: //www.pygtk.org/dist/pygtk2-tut.pdf)。 – katrielalex 2012-03-24 14:13:08
拖動滾動?請參閱http://stackoverflow.com/q/9311439/240633 – ergosys 2012-03-24 22:03:52