Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can set the width of your list control manually and then set the proportion to 0. </p> <p>The width of columns can be set manually:</p> <pre><code>import wx class MainWindow(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.panel = wx.Panel(self) self.panel.SetBackgroundColour(wx.GREEN) self.list = wx.ListCtrl(self, style=wx.LC_REPORT, size=(200, -1)) column_size = self.list.GetSize()[0] / 2 - 2 self.list.InsertColumn(0, 'Name') self.list.InsertColumn(1, 'Age') self.list.SetColumnWidth(0, column_size) self.list.SetColumnWidth(1, column_size) self.sizer = wx.BoxSizer() self.sizer.Add(self.list, proportion=0, flag=wx.EXPAND) self.sizer.Add(self.panel, proportion=1, flag=wx.EXPAND) self.SetSizerAndFit(self.sizer) self.SetSize((600, 400)) self.Show() app = wx.App(False) win = MainWindow(None) app.MainLoop() </code></pre> <p>Or the ListCtrlAutoWidthMixin may be used:</p> <pre><code>import wx import wx.lib.mixins.listctrl as listmix class TestListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin): def __init__(self, *args, **kwargs): wx.ListCtrl.__init__(self, *args, **kwargs) listmix.ListCtrlAutoWidthMixin.__init__(self) class MainWindow(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.panel = wx.Panel(self) self.panel.SetBackgroundColour(wx.GREEN) self.list = TestListCtrl(self, style=wx.LC_REPORT, size=(200, -1)) self.list.InsertColumn(0, 'Name') self.list.InsertColumn(1, 'Age') self.sizer = wx.BoxSizer() self.sizer.Add(self.list, proportion=0, flag=wx.EXPAND) self.sizer.Add(self.panel, proportion=1, flag=wx.EXPAND) self.SetSizerAndFit(self.sizer) self.SetSize((600, 400)) self.Show() app = wx.App(False) win = MainWindow(None) app.MainLoop() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload