WxPython 的最佳画布 [英] Best Canvas for WxPython

查看:35
本文介绍了WxPython 的最佳画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名 Java 程序员,正在使用 Python 和最新版本的 WxPython 开发一个项目.在Java Swing 中,您可以通过覆盖JPanel 元素的paint 方法来绘制它们.

I am a Java programmer working on a project in Python and the latest version of WxPython. In Java Swing, you can draw on JPanel elements by overriding their paint method.

我正在 WxPython 中为 GUI 应用程序寻找类似的类.

I am looking for a similar class in WxPython for a GUI application.

我在这里看到了这个问题:

I saw this question here:

最适合在 wxPython 中绘图的画布?

但是项目没有更新的事实让我很担心.

but the fact that the projects are not being updated has me worried.

三年后,除了 FloatCanvas 或 OGL 之外,还有什么我应该研究的吗?

Three years later, is there anything else I should look into other than FloatCanvas or OGL?

最终用例我以不同的缩放程度绘制声波.

The end use case i drawing a sound waves at varying degrees of zoom.

推荐答案

只需使用 wx.Panel.

这里有一些关于绘图上下文函数的文档:

Here is some documentation on the drawing context functions:

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()

这篇关于WxPython 的最佳画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆