canvas教程

Best Canvas for WxPython

字号+ 作者:H5之家 来源:H5之家 2015-11-22 13:00 我要评论( )

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

Just use a wx.Panel.

Here is some documentation on the drawing context functions:

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

只使用一个wx.Panel。

这是在绘图上下文函数的一些文件:

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

在这里输入图像描述

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • Python中使用Tkinter画图

    Python中使用Tkinter画图

    2017-03-22 15:00

  • Python程序的执行原理

    Python程序的执行原理

    2017-03-11 10:00

  • Python小作业一(用户登录交互界面)

    Python小作业一(用户登录交互界面)

    2017-02-17 15:04

  • Tkinter教程之Canvas篇(4)

    Tkinter教程之Canvas篇(4)

    2016-08-28 10:00

网友点评
)