I am porting my old python 2.7 code to 3.6 with wxpython phoenix and struggling now with a wxdialog where I don't succeed to get the correct layout. All wigdets appear in the upper left corner of the window. Can anybody help?
I work with Python 3.6.4, wxpython 4.0.1 msw (phoenix). The XRC file was generated with wxFormBuilder 3.5.
This is what I expect (shown by wxFormBuilder):
And this is what I get:
Thank you in advance
Regards
Edit
I tried to get the sizer containing the button by self.m_button_ok.GetContainingSizer()
. This method returns None! Does that mean that there are no valuable Sizers?
Here is my code:
import wx
import wx.xrc
class CTestDialog( wx.Dialog ):
def __init__( self, parent ):
wx.Dialog.__init__( self )
self.Create( parent, wx.ID_ANY, 'my Dlg Title' )
self._resources = wx.xrc.XmlResource( 'TestDialog.xrc' )
self._resources.LoadDialog( self, 'CTestDialog' )
self.m_button_ok = self._resources.LoadObjectRecursively( self, 'm_button_ok', 'wxButton' )
self.m_textCtrl_name = self._resources.LoadObjectRecursively( self, 'm_textCtrl_name', 'wxTextCtrl' )
button_sizer = self.m_button_ok.GetContainingSizer() # button_sizer is None
self.Layout()
if __name__ == "__main__":
app = wx.App( redirect=False )
dlg = CTestDialog( None )
dlg.ShowModal()
And the XRC file:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
<object class="wxDialog" name="CTestDialog">
<style>wxDEFAULT_DIALOG_STYLE</style>
<title>Test</title>
<centered>1</centered>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<option>1</option>
<flag>wxEXPAND|wxLEFT|wxRIGHT|wxTOP</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxLEFT|wxTOP</flag>
<border>3</border>
<object class="wxStaticText" name="m_staticText_name">
<size>80,-1</size>
<label>Name</label>
<wrap>-1</wrap>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxBOTTOM|wxRIGHT</flag>
<border>3</border>
<object class="wxTextCtrl" name="m_textCtrl_name">
<size>180,-1</size>
<value></value>
</object>
</object>
</object>
</object>
<object class="sizeritem">
<option>1</option>
<flag>wxALIGN_RIGHT|wxALL|wxEXPAND</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxLEFT</flag>
<border>50</border>
<object class="wxButton" name="m_button_ok">
<label>_OK</label>
<default>0</default>
</object>
</object>
</object>
</object>
</object>
</object>
</resource>
Found a solution, this code works. Anyhow I have the feeling that it is not the right way, since
CTestDialog
is no more awxDialog
class. The comments in the code explain what I changed.