Right panel is still visible although I set its size to (0,0)

In the code below, I want the right panel be “not visible” in the beginning, so I set its size to (0,0), but it is still visible when I run the script. What should I do:

import wx
import wx.grid as gridlib

···

########################################################################
class LeftPanel(wx.Panel):
“”""""

#----------------------------------------------------------------------
def __init__(self, parent):
    """Constructor"""
    wx.Panel.__init__(self, parent=parent)

    grid = gridlib.Grid(self)
    grid.CreateGrid(2,2)

    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(grid, 0, wx.EXPAND)
    self.SetSizer(sizer)

########################################################################
class RightPanel(wx.Panel):
“”""""

#----------------------------------------------------------------------
def __init__(self, parent):
    """Constructor"""
    wx.Panel.__init__(self, parent=parent)
    txt = wx.TextCtrl(self)

class MyForm(wx.Frame):

def __init__(self):
    wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial")

    leftP = LeftPanel(self)
    rightP = RightPanel(self)

    sizer = wx.BoxSizer(wx.HORIZONTAL)
    sizer.Add(leftP, 1, wx.EXPAND)
    sizer.Add(rightP, 1, wx.EXPAND)
    self.SetSizer(sizer)
    rightP.SetSize((0,0))

Run the program

if name == “main”:
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()

rightP.Show(False)

···

On Wednesday, July 30, 2014 11:54:46 AM UTC-7, steve wrote:

In the code below, I want the right panel be “not visible” in the beginning, so I set its size to (0,0), but it is still visible when I run the script. What should I do:

import wx
import wx.grid as gridlib

########################################################################
class LeftPanel(wx.Panel):
“”“”“”

#----------------------------------------------------------------------
def __init__(self, parent):
    """Constructor"""
    wx.Panel.__init__(self, parent=parent)

    grid = gridlib.Grid(self)
    grid.CreateGrid(2,2)

    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(grid, 0, wx.EXPAND)
    self.SetSizer(sizer)

########################################################################
class RightPanel(wx.Panel):
“”“”“”

#----------------------------------------------------------------------
def __init__(self, parent):
    """Constructor"""
    wx.Panel.__init__(self, parent=parent)
    txt = wx.TextCtrl(self)

class MyForm(wx.Frame):

def __init__(self):
    wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial")


    leftP = LeftPanel(self)
    rightP = RightPanel(self)





    sizer = wx.BoxSizer(wx.HORIZONTAL)
    sizer.Add(leftP, 1, wx.EXPAND)
    sizer.Add(rightP, 1, wx.EXPAND)
    self.SetSizer(sizer)
    rightP.SetSize((0,0))

Run the program

if name == “main”:
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()

But I want to use SetSize() method. Why doesn’t this method work?

···

On Wednesday, July 30, 2014 10:17:51 PM UTC+3, Nathan McCorkle wrote:

rightP.Show(False)

On Wednesday, July 30, 2014 11:54:46 AM UTC-7, steve wrote:

In the code below, I want the right panel be “not visible” in the beginning, so I set its size to (0,0), but it is still visible when I run the script. What should I do:

import wx
import wx.grid as gridlib

########################################################################
class LeftPanel(wx.Panel):
“”“”“”

#----------------------------------------------------------------------
def __init__(self, parent):
    """Constructor"""
    wx.Panel.__init__(self, parent=parent)

    grid = gridlib.Grid(self)
    grid.CreateGrid(2,2)

    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(grid, 0, wx.EXPAND)
    self.SetSizer(sizer)

########################################################################
class RightPanel(wx.Panel):
“”“”“”

#----------------------------------------------------------------------
def __init__(self, parent):
    """Constructor"""
    wx.Panel.__init__(self, parent=parent)
    txt = wx.TextCtrl(self)

class MyForm(wx.Frame):

def __init__(self):
    wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial")


    leftP = LeftPanel(self)
    rightP = RightPanel(self)





    sizer = wx.BoxSizer(wx.HORIZONTAL)
    sizer.Add(leftP, 1, wx.EXPAND)
    sizer.Add(rightP, 1, wx.EXPAND)
    self.SetSizer(sizer)
    rightP.SetSize((0,0))

Run the program

if name == “main”:
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()

But I want to use SetSize() method.

why? you want it to not be visible -- make it not visible.

Why doesn't this method work?

it could have a MinSize that is non-zero -- I'm not sure the wx supports
zero-sized visible windows at all -- in any case, it's likely to be
platform dependent.

-Chris

···

On Wed, Jul 30, 2014 at 12:18 PM, steve <oslocourse@gmail.com> wrote:

On Wednesday, July 30, 2014 10:17:51 PM UTC+3, Nathan McCorkle wrote:

rightP.Show(False)

On Wednesday, July 30, 2014 11:54:46 AM UTC-7, steve wrote:

In the code below, I want the right panel be "not visible" in the
beginning, so I set its size to (0,0), but it is still visible when I run
the script. What should I do:

import wx
import wx.grid as gridlib

########################################################################
class LeftPanel(wx.Panel):
    """"""

    #-----------------------------------------------------------
-----------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent=parent)

        grid = gridlib.Grid(self)
        grid.CreateGrid(2,2)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(grid, 0, wx.EXPAND)
        self.SetSizer(sizer)

########################################################################
class RightPanel(wx.Panel):
    """"""

    #-----------------------------------------------------------
-----------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent=parent)
        txt = wx.TextCtrl(self)

class MyForm(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial")

        leftP = LeftPanel(self)
        rightP = RightPanel(self)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(leftP, 1, wx.EXPAND)
        sizer.Add(rightP, 1, wx.EXPAND)
        self.SetSizer(sizer)
        rightP.SetSize((0,0))

# Run the program
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm()
    frame.Show()
    app.MainLoop()

--

You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

My guess is because it’s in a sizer, which is setting the size after/during the Show event (I could be wrong on that).

It is suggested that users always use a ‘main’ panel to add other stuff to… rather than adding other widgets directly to the Frame, or setting a sizer on the Frame.

I attempted some things, but they didn’t work. I definitely think it’s the sizer.

I didn’t check, but I added the widget inspector. Once the Frame is displayed, type CTRL-ALT-I and the inspector should pop up, letting you look through the size values for each widget.

t1.py (1.94 KB)

···

On Wednesday, July 30, 2014 12:18:26 PM UTC-7, steve wrote:

But I want to use SetSize() method. Why doesn’t this method work?

On Wednesday, July 30, 2014 10:17:51 PM UTC+3, Nathan McCorkle wrote:

rightP.Show(False)

On Wednesday, July 30, 2014 11:54:46 AM UTC-7, steve wrote:

In the code below, I want the right panel be “not visible” in the beginning, so I set its size to (0,0), but it is still visible when I run the script. What should I do:

import wx
import wx.grid as gridlib

########################################################################
class LeftPanel(wx.Panel):
“”“”“”

#----------------------------------------------------------------------
def __init__(self, parent):
    """Constructor"""
    wx.Panel.__init__(self, parent=parent)

    grid = gridlib.Grid(self)
    grid.CreateGrid(2,2)

    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(grid, 0, wx.EXPAND)
    self.SetSizer(sizer)

########################################################################
class RightPanel(wx.Panel):
“”“”“”

#----------------------------------------------------------------------
def __init__(self, parent):
    """Constructor"""
    wx.Panel.__init__(self, parent=parent)
    txt = wx.TextCtrl(self)

class MyForm(wx.Frame):

def __init__(self):
    wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial")


    leftP = LeftPanel(self)
    rightP = RightPanel(self)





    sizer = wx.BoxSizer(wx.HORIZONTAL)
    sizer.Add(leftP, 1, wx.EXPAND)
    sizer.Add(rightP, 1, wx.EXPAND)
    self.SetSizer(sizer)
    rightP.SetSize((0,0))

Run the program

if name == “main”:
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()