GetPostion() bug with position of -1?
7stud
bbxx789_05ss at yahoo.com
Tue Nov 20 13:40:50 PST 2007
The following program allows the user to move a frame around with key presses.
The frame moves one unit in any direction depending on what arrow key is
pressed. However, when I use SetPosition() to set the x or y position of the
frame to -1, subsequently GetPosition() reports the position as 0, which
prevents the key presses from moving the frame into a location with negative
coordinates. However, if I move the frame's x or y coordinate to -2, then
GetPostion() reports the correct coordinates, and allows the frame to move to
locations with negative coordinates.
import wx
class MyFrame(wx.Frame):
def __init__(self, parent=None, id=-1):
wx.Frame.__init__(self, parent, id)
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
def OnKeyDown(self, event):
key = event.GetKeyCode()
origin = self.GetPosition()
print origin
if key == 314: #left
print origin.x - 1
self.SetPosition((origin.x-1, origin.y))
elif key == 316: #right
self.SetPosition((origin.x+1, origin.y))
elif key == 315: #up
print origin.y - 1
self.SetPosition((origin.x, origin.y-1))
elif key == 317: # down
self.SetPosition((origin.x, origin.y+1))
print key
app = wx.App(redirect=False)
frame = MyFrame()
frame.Show()
app.MainLoop()
Is that a bug in GetPosition()?
More information about the wxpython-users
mailing list