Weird wx.Dialog behaviour

Greetings everyone. I’m having a problem that is driving me crazy.
If I test a dialog with a small program setting it as a top window, it’s displayed as designed. If I call it from another program, it’s both wider and higher. Any idea why this would happen?
An example (standalone version left, the other one right):


import wx

ID_BITMAPBUTTON1 = wx.ID_HIGHEST + 1
ID_STATICTEXT1 = wx.ID_HIGHEST + 2
ID_STATICTEXT2 = wx.ID_HIGHEST + 3
ID_STATICTEXT3 = wx.ID_HIGHEST + 4
ID_TEXTCTRL1 = wx.ID_HIGHEST + 5
ID_TEXTCTRL2 = wx.ID_HIGHEST + 6
ID_TEXTCTRL3 = wx.ID_HIGHEST + 7

class newdb(wx.Dialog):
def init ( self, parent ) :

    wx.Dialog.__init__(self, parent, id = wx.ID_ANY, title = "Create database", pos = wx.DefaultPosition,
                       size = wx.Size(550,350), style = wx.DEFAULT_DIALOG_STYLE)

    self.SetSizeHints( wx.Size(550,350), wx.Size(550,350) )

    fgSizer9 = wx.FlexGridSizer( 4, 2, 0, 0 )
    fgSizer9.SetFlexibleDirection( wx.BOTH )
    fgSizer9.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )

    fgSizer10 = wx.FlexGridSizer( 4, 1, 0, 0 )
    fgSizer10.SetFlexibleDirection( wx.BOTH )
    fgSizer10.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )

    self.ID_STATICTEXT1 = wx.StaticText( self, wx.ID_ANY, "Alias", wx.DefaultPosition, wx.DefaultSize, 0 )
    self.ID_STATICTEXT1.Wrap( 0 )

    fgSizer10.Add( self.ID_STATICTEXT1, 1, wx.ALL|wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 5 )

    self.ID_STATICTEXT2 = wx.StaticText( self, wx.ID_ANY, "File", wx.DefaultPosition, wx.DefaultSize, 0 )
    self.ID_STATICTEXT2.Wrap( 0 )

    fgSizer10.Add( self.ID_STATICTEXT2, 1, wx.ALL|wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 5 )

    self.ID_STATICTEXT3 = wx.StaticText( self, wx.ID_ANY, "Description", wx.DefaultPosition, wx.DefaultSize, 0 )
    self.ID_STATICTEXT3.Wrap( 0 )

    fgSizer10.Add( self.ID_STATICTEXT3, 1, wx.ALL|wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 5 )


    fgSizer9.Add( fgSizer10, 1, wx.ALL|wx.ALIGN_LEFT|wx.ALIGN_TOP, 5 )

    fgSizer11 = wx.FlexGridSizer( 4, 1, 0, 0 )
    fgSizer11.SetFlexibleDirection( wx.BOTH )
    fgSizer11.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )

    self.aliasctrl = wx.TextCtrl( self, ID_TEXTCTRL1, wx.EmptyString, wx.DefaultPosition, wx.Size( 114,27 ), 0 )
    self.aliasctrl.SetMaxLength( 0 )
    fgSizer11.Add( self.aliasctrl, 1, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL, 5 )

    fgSizer12 = wx.FlexGridSizer( 1, 2, 0, 0 )
    fgSizer12.SetFlexibleDirection( wx.BOTH )
    fgSizer12.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )

    self.filenamectrl = wx.TextCtrl( self, ID_TEXTCTRL2, wx.EmptyString, wx.DefaultPosition, wx.Size( 333,27 ), wx.TE_READONLY )
    self.filenamectrl.SetMaxLength( 0 )
    fgSizer12.Add( self.filenamectrl, 1, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5 )

    self.openbtn = wx.BitmapButton( self, ID_BITMAPBUTTON1, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW|wx.BU_AUTODRAW )

    self.openbtn.SetAuthNeeded()

    self.openbtn.SetBitmap( wx.Bitmap( "./bitmaps/disk.xpm", wx.BITMAP_TYPE_ANY ) )
    self.openbtn.SetToolTip( "Open file" )

    fgSizer12.Add( self.openbtn, 1, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5 )


    fgSizer11.Add( fgSizer12, 1, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL, 5 )

    self.descripctrl = wx.TextCtrl( self, ID_TEXTCTRL3, wx.EmptyString, wx.DefaultPosition, wx.Size( 333,27 ), 0 )
    self.descripctrl.SetMaxLength( 0 )
    fgSizer11.Add( self.descripctrl, 1, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL, 5 )

    bSizer7 = wx.BoxSizer( wx.HORIZONTAL )

    self.okbtn = wx.BitmapButton( self, wx.ID_OK, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW|wx.BU_AUTODRAW )
    self.okbtn.SetDefault()
    self.okbtn.SetAuthNeeded()

    self.okbtn.SetBitmap( wx.Bitmap( "./bitmaps/tick.xpm", wx.BITMAP_TYPE_ANY ) )
    self.okbtn.SetToolTip( "Confirm choices" )

    bSizer7.Add( self.okbtn, 1, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5 )

    self.cancelbtn = wx.BitmapButton( self, wx.ID_CANCEL, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW|wx.BU_AUTODRAW )

    self.cancelbtn.SetAuthNeeded()

    self.cancelbtn.SetBitmap( wx.Bitmap( "./bitmaps/cross.xpm", wx.BITMAP_TYPE_ANY ) )
    self.cancelbtn.SetToolTip( "Discard choices" )

    bSizer7.Add( self.cancelbtn, 1, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 5 )


    fgSizer11.Add( bSizer7, 1, wx.LEFT|wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 5 )


    fgSizer9.Add( fgSizer11, 1, wx.LEFT|wx.RIGHT|wx.TOP|wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_TOP, 5 )


    self.SetSizer( fgSizer9 )
    self.Layout()
    fgSizer9.Fit( self )

    self.Centre( wx.BOTH )        

def OnopenbtnClick(self, event):
    event.Skip()

Hi and welcome to Discuss wxPython,

I tested your code using Python 3.10.12 + wxPython 4.2.1 gtk3 (phoenix) wxWidgets 3.2.2.1 on Linux Mint 21.2

I found that I got the same large dialog when run on its own and when run as a child of a Frame.

To run the dialog on its own I added:

app = wx.App()
dlg = newdb(None)
dlg.ShowModal()
app.MainLoop()

To run it as a child of a Frame I added:

class MyFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent)
        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)
        button = wx.Button(panel, -1, "Dialog")
        sizer.Add(button, 0, wx.ALL, 16)
        panel.SetSizer(sizer)
        sizer.Layout()
        self.Bind(wx.EVT_BUTTON, self.OnDialog, button)

    def OnDialog(self, _event):
        dlg = newdb(self)
        dlg.ShowModal()
        dlg.Destroy()


app = wx.App()
frame = MyFrame(None)
frame.Show()
app.MainLoop()

However, if I commented out the SetSizeHints() call, I got the small dialog in both cases.

I also got the small dialog in both cases if I replaced the call to SetSizeHints() by self.SetSize((550, 350)).

Thanks a lot!
I also found another problem in other parts of the program, due to the code generators I was using.
At the end of the creation of the dialogs, it adds the following line

self.SetSizerAndFit(Sizer1)

I found out that replacing it with:

self.SetSizer(FlexGridSizer1)
self.Layout()
FlexGridSizer1.Fit(self)

Does the trick. No more oversized dialogs!