[英]problem when zooming pictures in wxpython
我需要在滚动面板中绘制图像(以对其进行评论)。 我遇到了麻烦,因为放大或缩小时它的行为都不正确。 它停止绘制,然后过一会儿在错误的位置显示它。 在窗口的左上角。 并且没有正确地画线。 以下是( onLeftDown
)函数(应绘制的按钮)的代码。 右键事件(放大)。 希望它足够清楚。
你们知道发生了什么吗,我该如何解决?
提前致谢
def OnLeftButtonEvent(self, event):
self.curLine = []
self.x, self.y = event.GetPositionTuple()
self.CaptureMouse()
def OnMotion(self, event):
if self.HasCapture() and event.Dragging():
dc = wx.BufferedDC(None,self.buffer)
dc.SetUserScale(self.scale,self.scale)
# to zoom in and out ( increases whenever someone presses the right mouse button
dc.BeginDrawing()
dc.SetPen(wx.Pen(wx.BLUE, 3))
coords = (self.x, self.y) + event.GetPositionTuple()
self.curLine.append(coords)
dc.DrawLine(*coords)
self.x, self.y = event.GetPositionTuple()
self.SetXY(event)
dc.EndDrawing()
def OnRightDown(self,event):
print self.scale
self.scale=self.scale*2.0
self.initDrawing()
self.maxHeight=self.maxHeight*2
self.maxWidth=self.maxWidth*2
您需要缩放鼠标坐标,以使其与绘图的缩放同步,因此,如果您使用userScale = 2,则x = 10处的鼠标将以20结尾。 所以你需要这样做
sx, sy = x/cur_scale, y/cur_scale
您还需要在EVT_PAINT
事件中进行绘制, EVT_PAINT
不是在onmotion上进行绘制,在运动中,您只需要刷新窗口即可,paint事件应该照顾您要绘制的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.