I observed that there is a difference with respect to how float arguments to wxPython (4.2.1) methods are handled. With python 3.9 floats are accepted and the results are as expected. With python 3.10 floats are accepted in the sense that there is no warning but converted to zero. This is true for at least wx.Window.SetMinSize and wx.DeviceContext.DrawText put possibly other methods as well.
It happens on windows 10 and 11 on several machines.
See the most relevant topic here.
Could you try with wxpyhton 4.2.1? I do not get any errors but as I said all floats seem to be converted to 0.
What parameters are you passing to
I can only test on linux, but I notice that if I pass a tuple containing a float to
then it doesn’t raise an exception.
However, if I try to create a
wx.Size object from a float in order to pass to
sz = wx.Size(300.5, 300) self.SetMinSize(sz)
then it does raise an exception:
Traceback (most recent call last): File "/home/richardt/Development/python/exp/hci/wxpython/frame/frame_size/set_size/set_frame_size2.py", line 77, in OnInit self.frame = MyFrame(None, wx.ID_ANY, "") File "/home/richardt/Development/python/exp/hci/wxpython/frame/frame_size/set_size/set_frame_size2.py", line 23, in __init__ sz = wx.Size(300.5, 300) TypeError: Size(): arguments did not match any overloaded call: overload 1: too many arguments overload 2: argument 1 has unexpected type 'float' overload 3: argument 1 has unexpected type 'float' OnInit returned false, exiting...
Perhaps when a tuple is passed to
SetMinSize(), the value in the tuple is converted to ints purely in python, before it’s passed to the C++ code; whereas when a float is passed to
wx.Size() it gets passed directly to the C++ code and thus triggers the
Do you have a small, runnable sample program that demonstrates the problem and also shows how you are determining that the float has been converted to zero?
Note: I am using Python 3.10.12 + wxPython 4.2.1 gtk3 (phoenix) wxWidgets 188.8.131.52 on Linux Mint 21.2
but is None and not executed
Without wishing to be accused of being a code nazi or pointing out ‘the bleeding obvious’, is it reasonable to expect a pixel position to be defined as a float?
Or, that other code make up for the deficiencies in your own code?
These corrections can and do happen, all the time and whilst a bit annoying are legitimate.
self.SetMinSize((300.5, 300)) to blow up in the next iteration too!
On Linux, it seems that any float that is passed in the tuple is silently ignored and the default value is used.
import wx class MyFrame(wx.Frame): def __init__(self, *args, **kwds): wx.Frame.__init__(self, *args, **kwds) self.SetSize((400, 200)) self.SetTitle("SetMinSize() Test") self.panel_1 = wx.Panel(self, wx.ID_ANY) sizer_1 = wx.BoxSizer(wx.HORIZONTAL) self.button_1 = wx.Button(self.panel_1, wx.ID_ANY, "button_1") # If you pass two ints in a tuple they will both be used: self.button_1.SetMinSize((150, 150)) sizer_1.Add(self.button_1, 0, wx.RIGHT, 8) self.button_2 = wx.Button(self.panel_1, wx.ID_ANY, "button_2") # If you pass one int and one float, the int will # be used, but the float will be silently ignored self.button_2.SetMinSize((150.5, 150)) sizer_1.Add(self.button_2, 0, wx.RIGHT, 8) self.button_3 = wx.Button(self.panel_1, wx.ID_ANY, "button_3") # If you pass two floats in a tuple they will both be silently ignored: self.button_3.SetMinSize((150.5, 150.5)) sizer_1.Add(self.button_3, 0, 0, 0) self.panel_1.SetSizer(sizer_1) self.Layout() for b in self.button_1, self.button_2, self.button_3: print(b.GetSize()) app = wx.App() frame = MyFrame(None, wx.ID_ANY, "") frame.Show() app.MainLoop()
Edit: program output:
(150, 150) (85, 150) (85, 30)
well, I think many (if not many, many…) people go sort of trial & error (if it’s complicated most of them) and then, of course, a compilation is the answer (not dynamic)
the problem is if the size is computed (one can’t see it easily) and the quiet substitution is taken away
that is why magic isn’t always magic @RichardT (I think this is work in progress, or the other way round )
@da-dada Real magic would be if it could avoid this:
self.label.SetMinSize("two hundred", "three hundred") TypeError: Window.SetMinSize(): argument 1 has unexpected type 'str'