我不知道這是你在找什麼,但是如果你在你的模塊中創建了另一個窗口,並且當你釋放拖拽時讓你的代碼顯示它呢?你可以獲取光標的當前位置,並在那裏繪製窗口。
This should help you get the mouse position on the root window.
所以,你的代碼可能看起來有點像這樣(這是未經測試的代碼!)我只顯示了什麼走了進去__ __初始化的相關部分。
def __init__(self):
...
#Some of your code here.
...
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
#Note that I am creating a popup window separately.
popwin = gtk.Window(gtk.WINDOW_POPUP)
#I am setting "decorated" to False, so it will have no titlebar or window controls.
#Be sure to compensate for this by having another means of closing it.
popwin.set_decorated(False)
def ShowPopup():
#You may need to put additional arguments in above if this is to be an event.
#For sake of example, I'm leaving this open ended.
#Get the cursor position.
rootwin = widget.get_screen().get_root_window()
curx, cury, mods = rootwin.get_pointer()
#Set the popup window position.
popwin.move(curx, cury)
popwin.show()
def HidePopup():
#This is just an example for how to hide the popup when you're done with it.
popwin.hide()
...
#More of your code here.
...
#Of course, here is the code showing your program's main window automatically.
win.show()
一個非常簡單的方法,但它應該給出你想要的外觀。
你可以用pygtk處理onclick/release處理程序嗎?你能在屏幕上畫一個盒子嗎?如果是這樣,你還需要什麼? –
問題最難的部分是在根窗口上繪製一個框 - 而不是在子窗口/小部件上。我沒有使用pygtk在根窗口上繪製任何東西。 – jwegner