Sizer's wx.EXPAND does not GROW

In a frame of mine there is a wx.BoxSizer(wx.HORIZONTAL) named gsizer that contains some buttons.
I build another wx.BoxSizer(wx.HORIZONTAL) named txsizer, with a wx.TextCtrl named txt and added with txsizer.Add(txt, stretcher, wx.GROW).

I then add txsizer to gsizer with the commands
gsizer.Add(txsizer, stretcher, wx.EXPAND)
self.Layout()
self.Fit()
but whatever the value I give to “stretcher” txt keeps it original width.

Anybody sees where is my mistake?

raffaello wrote:

In a frame of mine there is a wx.BoxSizer(wx.HORIZONTAL) named gsizer that contains some buttons.
I build another wx.BoxSizer(wx.HORIZONTAL) named txsizer, with a wx.TextCtrl named txt and added with txsizer.Add(txt, stretcher, wx.GROW).
I then add txsizer to gsizer with the commands
      gsizer.Add(txsizer, stretcher, wx.EXPAND)
      self.Layout()
      self.Fit()
but whatever the value I give to "stretcher" txt keeps it original width.
Anybody sees where is my mistake?

Well, I suspect we'd need a small runnable sample to demonstrate the issue. You are using a HORIZONTAL sizer, so the EXPAND/GROW is defining how to EXPAND in the VERTICAL direction. The stretcher will define how much space to take up horizontally in this case, so a value of 1, assuming there are no other controls with a non-zero proportion, should make it take up the entire horizontal space that txsizer has. So, your issue may be that txsizer or gsizer aren't as wide as you think they are, and as such the text control has no room to take up horizontally anyway.

One thing you don't show in your code is what gsizer is added to or assigned to. That could be the issue as well.

- Mike

Thanks, Mike. Please find here attached the shortest possible sample showing my problem. I’ll appreciate any help.

SizerTest.py (2.01 KB)

···

2008/8/4 Mike Rooney mxr@qvii.com

raffaello wrote:

In a frame of mine there is a wx.BoxSizer(wx.HORIZONTAL) named gsizer that contains some buttons.

I build another wx.BoxSizer(wx.HORIZONTAL) named txsizer, with a wx.TextCtrl named txt and added with txsizer.Add(txt, stretcher, wx.GROW).

I then add txsizer to gsizer with the commands

  gsizer.Add(txsizer, stretcher, wx.EXPAND)

  self.Layout()

  self.Fit()

but whatever the value I give to “stretcher” txt keeps it original width.

Anybody sees where is my mistake?

Well, I suspect we’d need a small runnable sample to demonstrate the issue. You are using a HORIZONTAL sizer, so the EXPAND/GROW is defining how to EXPAND in the VERTICAL direction. The stretcher will define how much space to take up horizontally in this case, so a value of 1, assuming there are no other controls with a non-zero proportion, should make it take up the entire horizontal space that txsizer has. So, your issue may be that txsizer or gsizer aren’t as wide as you think they are, and as such the text control has no room to take up horizontally anyway.

One thing you don’t show in your code is what gsizer is added to or assigned to. That could be the issue as well.

  • Mike

wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

raffaello wrote:

Thanks, Mike. Please find here attached the shortest possible sample showing my problem. I'll appreciate any help.

I've attached your code with minor tweaks, compare with the original to see what I changed. I think the root of your problem is that you have nested sizers you do not think that they need to be set to expand or to have a proportion value too. If the nested sizer can't expand then the items within it can't either.

SizerTest.py (2.13 KB)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

This is much more than ANY help.

I discovered sizers only a little time ago, but the more I learn about the more I like them. Many thanks.

···

2008/8/4 Robin Dunn robin@alldunn.com

raffaello wrote:

Thanks, Mike. Please find here attached the shortest possible sample showing my problem. I’ll appreciate any help.

I’ve attached your code with minor tweaks, compare with the original to see what I changed. I think the root of your problem is that you have nested sizers you do not think that they need to be set to expand or to have a proportion value too. If the nested sizer can’t expand then the items within it can’t either.

Robin Dunn

Software Craftsman

http://wxPython.org Java give you jitters? Relax with wxPython!

#!/usr/bin/env python

“”“SizerTest - 'cause Sizer’s wx.EXPAND does not GROW “””

import wx

print wx.version()

class SizerTest(wx.Frame):

def __init__(self):



    wx.Frame.__init__(self, parent = None, id = wx.ID_ANY)

    pn = wx.Panel(self)

    mainsizer = wx.BoxSizer(wx.VERTICAL)

    pn.SetSizer(mainsizer)

    firstsizer = wx.BoxSizer(wx.HORIZONTAL)

    mflag =  wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.GROW

    for i in range(6):

        firstsizer.Add(wx.Button(pn, wx.ID_ANY, label = str(i),\

            size = (30, 30)), 0, flag = mflag, border = 2)

    mainsizer.Add(firstsizer, 0, wx.EXPAND)



    text = wx.TextCtrl(pn, wx.ID_ANY, 'Stretta la foglia larga la via', \

        ) #size = (600, wx.ID_ANY))

    mainsizer.Add(text, 0, wx.EXPAND|wx.ALL , 3)

secondsizer = wx.BoxSizer(wx.VERTICAL)

secondsizer.Add(text, 0, wx.ALL , 3)

mainsizer.Add(secondsizer, 0, wx.ALL , 3)

(even this second solution does not work)

    # now the problen

    boxv = wx.BoxSizer(wx.VERTICAL)

    boxh = wx.BoxSizer(wx.HORIZONTAL)

    boxh.Add(wx.StaticText(pn, wx.ID_ANY, 'test: '), 0, wx.CENTER, 2)

    choice = wx.Choice(pn, wx.ID_ANY,  size = (200, wx.ID_ANY))

    boxh.Add(choice, 1, wx.ALIGN_RIGHT |wx.ALL |wx.EXPAND , 2)

    boxv.Add(boxh,0,  wx.EXPAND)

    shortertext = wx.TextCtrl(pn, wx.ID_ANY, 'Dite la vostra che ho detto la mia', \

    size = (300, wx.ID_ANY))

    boxv.Add(shortertext, 0, wx.EXPAND)



    firstsizer.Add(boxv, 1, wx.EXPAND)



    self.Layout()

    mainsizer.Layout()

    mainsizer.Fit(pn)

    self.Fit()

Comment:

In my intention, choice and shortertext should grow until their right

size is in the same x position as the righ side of text.

Note that if you resize the frame, the windows sizes do not change

if name == ‘main’:

app = wx.App()

frame = SizerTest()

frame.Show(True)

import wx.lib.inspection

wx.lib.inspection.InspectionTool().Show()

app.MainLoop()

wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users