2
A
回答
2
你看過wxPython演示了嗎?它有幾個使用wx.PopupWindow及其變體的例子。這裏是一個基於演示的例子:
import wx
########################################################################
class TestPopup(wx.PopupWindow):
""""""
#----------------------------------------------------------------------
def __init__(self, parent, style):
"""Constructor"""
wx.PopupWindow.__init__(self, parent, style)
panel = wx.Panel(self)
self.panel = panel
panel.SetBackgroundColour("CADET BLUE")
st = wx.StaticText(panel, -1,
"This is a special kind of top level\n"
"window that can be used for\n"
"popup menus, combobox popups\n"
"and such.\n\n"
"Try positioning the demo near\n"
"the bottom of the screen and \n"
"hit the button again.\n\n"
"In this demo this window can\n"
"be dragged with the left button\n"
"and closed with the right."
,
pos=(10,10))
sz = st.GetBestSize()
self.SetSize((sz.width+20, sz.height+20))
panel.SetSize((sz.width+20, sz.height+20))
panel.Bind(wx.EVT_LEFT_DOWN, self.OnMouseLeftDown)
panel.Bind(wx.EVT_MOTION, self.OnMouseMotion)
panel.Bind(wx.EVT_LEFT_UP, self.OnMouseLeftUp)
panel.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
st.Bind(wx.EVT_LEFT_DOWN, self.OnMouseLeftDown)
st.Bind(wx.EVT_MOTION, self.OnMouseMotion)
st.Bind(wx.EVT_LEFT_UP, self.OnMouseLeftUp)
st.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
wx.CallAfter(self.Refresh)
def OnMouseLeftDown(self, evt):
self.Refresh()
self.ldPos = evt.GetEventObject().ClientToScreen(evt.GetPosition())
self.wPos = self.ClientToScreen((0,0))
self.panel.CaptureMouse()
def OnMouseMotion(self, evt):
if evt.Dragging() and evt.LeftIsDown():
dPos = evt.GetEventObject().ClientToScreen(evt.GetPosition())
nPos = (self.wPos.x + (dPos.x - self.ldPos.x),
self.wPos.y + (dPos.y - self.ldPos.y))
self.Move(nPos)
def OnMouseLeftUp(self, evt):
if self.panel.HasCapture():
self.panel.ReleaseMouse()
def OnRightUp(self, evt):
self.Show(False)
self.Destroy()
########################################################################
class TestPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
btn = wx.Button(self, label="Open Popup")
btn.Bind(wx.EVT_BUTTON, self.onShowPopup)
#----------------------------------------------------------------------
def onShowPopup(self, event):
""""""
win = TestPopup(self.GetTopLevelParent(), wx.SIMPLE_BORDER)
btn = event.GetEventObject()
pos = btn.ClientToScreen((0,0))
sz = btn.GetSize()
win.Position(pos, (0, sz[1]))
win.Show(True)
########################################################################
class TestFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Test Popup")
panel = TestPanel(self)
self.Show()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = TestFrame()
app.MainLoop()
+0
謝謝!甚至沒有看到那個。 – LukeG
相關問題
- 1. WxPython窗口不彈出
- 2. 在wxpython中彈出窗口創建
- 3. Knockout Twitter Bootstrap彈出窗口綁定
- 4. 將引導彈窗輸入值綁定到擁有彈出窗口的元素
- 5. 彈出窗口:當彈出彈出窗口時關閉彈出
- 6. 無法將ajax數據綁定到彈出窗口?
- 7. 如何將事件綁定到彈出窗口?
- 8. 將unbeforeunload方法再次綁定到刷新的彈出窗口
- 9. 未指定大小時彈出窗口彈出窗口
- 10. 定位彈出窗口GWT
- 11. jQuery.mobile.splitview彈出窗口定位
- 12. 自定義窗口彈出
- 13. 在wxPython中,如何將EVT_KEY_DOWN事件綁定到整個窗口?
- 14. 彈出窗口
- 15. Android彈出窗口在彈出窗口外彈出時解僱
- 16. 關閉彈出窗口並重定向到父窗口在Struts2
- 17. 如何將主窗口從彈出窗口重定向到URL?
- 18. 關閉當前彈出窗口並重定向到父窗口
- 19. wxPython,wxButton上的多行標籤
- 20. 輸入綁定CommandParameter綁定到窗口
- 21. 彈出式彈性窗口
- 22. 如何彈出最小化的wxPython窗口
- 23. 退出彈出式窗口與彈出式窗口
- 24. 綁定到窗口標題
- 25. ie8彈出窗口
- 26. Javascript彈出窗口
- 27. 彈出窗口programmaticall
- 28. mvc彈出窗口
- 29. Javascript彈出窗口
- 30. javascript彈出窗口
你是什麼意思的「彈出窗口」?你想在用戶按下按鈕時打開一個新窗口嗎?或者你是否在尋找更像工具文本的東西,當用戶將鼠標放在按鈕上時顯示出來? – wnnmaw
我想要一個新窗口彈出另一個窗口。 – LukeG
這是您創建的新窗口嗎? (即你有一個班) – wnnmaw