Open JimCordwell opened 1 year ago
This is really a Python 3.9 -> 3.10 change. Most of the wxWidgets methods only accept integers. With Python 3.9 and lower, when passed floats, they would be silently truncated. Now, Python 3.10 will now throw an exception in these cases, so you'll have to convert them to ints yourself, e.g., use int(x)
.
@swt2c Thanks for the reply, I am now using the int cast to correct for this. The issue for me is that there is no exception raised in this case, so it took a little while to track down the problem. In the example I gave, half the call is completed, setting the height to the int value provided. I would assume therefore that internally the width & height are set independently, and possibly some error handling swallows an exception for attempting to set the width to a float in this case.
Oh so you are saying that SetPosition((100.0, 30))
doesn't throw an exception? That's strange - must be something in the conversion from a tuple to wxPoint.
Yes, that's right SetPosition fails silently but SetSize throws.
Windows 10 wxPython 4.2.0 pypi Python 3.10 x64 stock
wx.Button.SetPosition fails when provided a float value This worked with Python 3.9 x64 stock
Code Example (click to expand)
```python import wx class PositionTest(wx.Frame): def __init__(self): super().__init__(parent=None, title="Position Test", pos=(300,300), size=(640,480)) self.panel = wx.Panel(self, pos=(0,0), size=(self.Size)) self.btn = wx.Button(self.panel) print("Button initial posn" + str(self.btn.Position)) # (0,0) # Use of a float here worked in Python 3.9 fails without an error in Python 3.10 self.btn.SetPosition((100.0, 30)) print("Button posn after set" + str(self.btn.Position)) # now (0,30), should be (100, 30) # use of a float in SetSize results in a error # "Window.SetSize(): arguments did not match any overloaded call" self.btn.SetSize(50, 50) self.Show() if __name__ == '__main__': app = wx.App() window = PositionTest() app.MainLoop() ```