回答
任何UI庫都可能以某種方式支持此功能。在wxPython中,我們允許列表項在各種列表之間移動。事情可能是這樣的:
class JobList(VirtualList):
def __init__(self, parent, colref = 'job_columns'):
VirtualList.__init__(self, parent, colref)
def _bind(self):
VirtualList._bind(self)
self.Bind(wx.EVT_LIST_BEGIN_DRAG, self._startDrag)
def _startDrag(self, evt):
# Create a data object to pass around.
data = wx.CustomDataObject('JobIdList')
data.SetData(str([self.data[idx]['Id'] for idx in self.selected]))
# Create the dropSource and begin the drag-and-drop.
dropSource = wx.DropSource(self)
dropSource.SetData(data)
dropSource.DoDragDrop(flags = wx.Drag_DefaultMove)
然後,有一個ListDrop類,有利於東西到列表中的下落:
class ListDrop(wx.PyDropTarget):
"""
Utility class - Required to support List Drag & Drop.
Using example code from http://wiki.wxpython.org/ListControls.
"""
def __init__(self, setFn, dataType, acceptFiles = False):
wx.PyDropTarget.__init__(self)
self.setFn = setFn
# Data type to accept.
self.data = wx.CustomDataObject(dataType)
self.comp = wx.DataObjectComposite()
self.comp.Add(self.data)
if acceptFiles:
self.data2 = wx.FileDataObject()
self.comp.Add(self.data2)
self.SetDataObject(self.comp)
def OnData(self, x, y, d):
if self.GetData():
if self.comp.GetReceivedFormat().GetType() == wx.DF_FILENAME:
self.setFn(x, y, self.data2.GetFilenames())
else:
self.setFn(x, y, self.data.GetData())
return d
最後,那裏的東西可以被丟棄列表:
class QueueList(VirtualList):
def __init__(self, parent, colref = 'queue_columns'):
VirtualList.__init__(self, parent, colref)
self.SetDropTarget(ListDrop(self.onJobDrop, 'JobIdList', True))
def onJobDrop(self, x, y, data):
idx, flags = self.HitTest((x, y)) #@UnusedVariable
if idx == -1: # Not dropped on a list item in the target list.
return
# Code here to handle incoming data.
看起來很有希望。那是內部的wxPython或將它與其他Windows應用程序的工作?因爲我真正需要的是一些可拖動的標籤,它會在插入到Windows應用程序時插入字符串,所以我不擔心被刪除,我不需要複雜的對象,只需要一些字符串內容... – Gerenuk
@ Gerenuk - CustomDataObject是我的一個更好的選擇,但您也可以使用'wx.TextDataObject'或'wx.PyTextDataObject'。您可以在這裏找到更多信息:http://wiki.wxpython.org/ListControls#Drag_and_Drop_with_lists –
理論上,你可以使用其中一個圖形拖放和拖放設計存在任何庫。這些工具通常會生成標記語言,這些標記語言會被庫解析,有時它們會直接生成代碼。後者是語言依賴的,而前者不應該。無論哪種方式,您都可以找到一種使用Python的方法。
實際上,一些圖書館擁有更好的可視化設計工具。當我使用WinForms設計器時,它非常優雅和無縫,所以也許IronPython? PyGTK,Glade或前面提到的PyQt怎麼樣?也許在NetBeans中使用Swing設計Jython?
編輯:哎呦,我沒有正確讀取的問題。你要找的是一個具有拖放功能的框架,即大多數框架。有很多事情需要考慮,例如,目標窗口和源窗口將來自同一個進程?他們會用相同的框架編寫嗎?這些東西可能是相關的或不相關的,取決於它是如何被寫入的。
這是不同的過程。基本上,我想刪除文本字符串成任意的Windows應用程序。他們中的大多數支持。 – Gerenuk
- 1. 簡單的拖放在Windows Phone 8中
- 2. Android簡單的拖放庫
- 3. 簡單的拖放視圖?
- 4. Android簡單的拖放?
- 5. Flex:拖放,簡單示例
- 6. C++簡單的GUI爲Windows,Linux和Mac
- 7. XNA簡單的GUI框架爲Windows
- 8. 與拖放和簡單的GridView拖放重新排序
- 9. 主幹使用簡單的拖放
- 10. 簡單的jQuery拖放不工作
- 11. 不能簡單的WPF拖放工作
- 12. 簡單的拖放到目標as3
- 13. 我簡單的拖放功能口吃
- 14. 簡單的拖放和不工作
- 15. 簡單的拖放快速/ xcode
- 16. 簡單的jQuery UI拖放示例
- 17. 如何實現拖放gui?
- 18. Windows 10拖放
- 19. 簡單的拖動'n'拖放元素運動是生澀的
- 20. 拖/放於Windows 7
- 21. 拖放Windows窗體
- 22. 在Windows中拖放
- 23. 簡單的HTML5拖放文件網站網站,其中拖放的文件
- 24. Matlab從Windows資源管理器拖放文件到圖(gui)
- 25. 對win32 GUI的拖放支持
- 26. 帶拖放功能的Python HTML gui
- 27. 在GUI中的拖放操作
- 28. Windows保留拖放光標
- 29. 拖放Windows窗體按鈕
- 30. 簡單的Java GUI程序
你和誰一起工作過,你有什麼嘗試過?除了答案中提到的其他人之外,wxPython還全面支持拖放事件。 –
我只做了一些TkInter。無論如何,我想我必須重新學習它。所以我需要一個非常簡單的地方,我有機會找到在線示例,展示如何使小部件可拖動並提供一些關於拖動的文本。我只需要一個提供可拖動文本的按鈕列表。 – Gerenuk