wxPython关于图形显示的问题
先贴代码import wx
class SketchWindow(wx.Window):
def __init__(self, parent, ID):
wx.Window.__init__(self, parent, ID)
self.SetBackgroundColour("Black")
self.color = "red"
self.thickness = 1
self.pen = wx.Pen(self.color, self.thickness, wx.SOLID)
self.lines = []
self.curLine = []
self.pos = (0, 0)
self.reInitBuffer = True
self.Bind(wx.EVT_MOTION, self.test) #1
#self.test(1) #2
def InitBuffer(self):
size = self.GetClientSize() #3
#self.buffer = wx.EmptyBitmap(max(792, size.width), max(566, size.height))
self.buffer = wx.EmptyBitmap(size.width, size.height)
print self.buffer,size.width, size.height #4
if self.buffer.Ok():
dc = wx.BufferedDC(None, self.buffer)
dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
dc.Clear()
self.reInitBuffer = False
def drawMotion(self, dc):
dc.SetPen(self.pen)
newPos = (500,200)
self.pos = (200,500)
coords = self.pos + newPos
dc.DrawLine(*coords)
def test(self,evt):
self.OnIdle()
def OnIdle(self):
if self.reInitBuffer:
self.InitBuffer() #5
self.Refresh(False)
dc = wx.BufferedDC(wx.ClientDC(self), self.buffer)
self.drawMotion(dc)
print "OnIdle"
class SketchFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Sketch Frame",
size=(800,600))
self.sketch = SketchWindow(self, -1)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = SketchFrame(None)
frame.Show(True)
app.MainLoop()
问题:
当我调用#1注释#2的时候,程序能正常显示(黑色背景上有一条红线),
当我调用#2注释#1的时候,程序不能正常显示,
区别事#3取得的size不一样,InitBuffer() 是在#5地方被调用的,请高手解释下原因以及解决不用事件驱动能产生图形的办法,谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://v.ku6.com/show/kSH6Sgg-2q-KpE-H.html