我正在使用 wxpython phoenix 将旧的 python 2.7 代码移植到 3.6,现在正在使用 wxdialog 苦苦挣扎,我无法成功获得正确的布局。所有 wigdets 都出现在窗口的左上角。有人可以帮忙吗?
我使用 Python 3.6.4、wxpython 4.0.1 msw (phoenix)。XRC 文件是使用 wxFormBuilder 3.5 生成的。
这是我所期望的(由 wxFormBuilder 显示):
这就是我得到的:
先感谢您
问候
编辑
我试图通过self.m_button_ok.GetContainingSizer()
. 此方法返回无!这是否意味着没有有价值的 Sizer?
这是我的代码:
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()
XRC 文件:
<?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>