2013-05-16 81 views
3

我是一位從事Python項目和最新版本WxPython的Java程序員。在Java Swing中,您可以通過覆蓋它們的繪製方法來繪製JPanel元素。適用於WxPython的最佳畫布

我要尋找一個在wxPython中有一個類似的類GUI應用程序。

我看到這個問題在這裏:

Best canvas for drawing in wxPython?

但事實證明,這些項目都沒有更新了我的擔心。

三年後,還有什麼我應該考慮除了FloatCanvas或OGL?

最終用途情況下,我在不同程度的縮放的繪製聲波。

回答

6

只需使用一個wx.Panel

這裏是在繪圖方面功能的一些文檔:

http://docs.wxwidgets.org/stable/wx_wxdc.html

http://www.wxpython.org/docs/api/wx.DC-class.html

import wx 

class View(wx.Panel): 
    def __init__(self, parent): 
     super(View, self).__init__(parent) 
     self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) 
     self.Bind(wx.EVT_SIZE, self.on_size) 
     self.Bind(wx.EVT_PAINT, self.on_paint) 
    def on_size(self, event): 
     event.Skip() 
     self.Refresh() 
    def on_paint(self, event): 
     w, h = self.GetClientSize() 
     dc = wx.AutoBufferedPaintDC(self) 
     dc.Clear() 
     dc.DrawLine(0, 0, w, h) 
     dc.SetPen(wx.Pen(wx.BLACK, 5)) 
     dc.DrawCircle(w/2, h/2, 100) 

class Frame(wx.Frame): 
    def __init__(self): 
     super(Frame, self).__init__(None) 
     self.SetTitle('My Title') 
     self.SetClientSize((500, 500)) 
     self.Center() 
     self.view = View(self) 

def main(): 
    app = wx.App(False) 
    frame = Frame() 
    frame.Show() 
    app.MainLoop() 

if __name__ == '__main__': 
    main() 

enter image description here

+0

你如何處理這樣的 「畫布」 縮放? – Basj

+0

嘗試'dc.SetUserScale' - http://www.wxpython.org/docs/api/wx.DC-class.html#SetUserScale – FogleBird