add button hide in canvas wxpython4

hi ,

i need to add hide button in canvas i the same panel how can i do that how i can have space to add the button ?

i have no idea if is possible to add button in two canvas button ’ plot" like the picture :

that is my code with 2 panels and 2 canvas

import wx
from numpy import arange, sin, pi,cos
import numpy as np
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.widgets import RectangleSelector
from matplotlib.figure import Figure

class MainFrame(wx.Frame):
def init(self, parent ):
wx.Panel.init(self, parent,name=“Main”, size = (600,800))
Top = PanelTop(self)
Bottom = PanelBottom(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(Top, 1, wx.EXPAND)
sizer.Add(Bottom, 1, wx.EXPAND)
self.SetSizer(sizer)

class PanelTop(wx.Panel):
def init(self,parent):
wx.Panel.init(self,parent,size = (300,300))
self.SetBackgroundColour(‘white’)
self.figure = Figure(figsize = (4,5))
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self,-1,self.figure)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(self.sizer)

    t = arange(0.5, 3.0, 0.01)
    s = cos(2 * pi * t)
    self.axes.plot(t, s)

class PanelBottom(wx.Panel):
def init(self,parent):
wx.Panel.init(self, parent, size = (300,300))
self.SetBackgroundColour(‘grey77’)
self.figure = Figure(figsize = (4,5))
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self,-1,self.figure)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(self.sizer)

    t = arange(0.0, 3.0, 0.01)
    s = sin(2 * pi * t)
    self.axes.plot(t, s)

app = wx.App()
frame = MainFrame(None).Show()
app.MainLoop()

thank you

Maj wrote:

i need to add hide button in canvas i the same panel how can i do that how i can have space to add the button ?
i have no idea if is possible to add button in two canvas button ' plot" like the picture :

Of course it is. You just need to decide where they should go. Here's a version of your code with the buttons in between the two panels.

One little comment -- you had this in your code:

 class MainFrame\(wx\.Frame\):
     def \_\_init\_\_\(\*self, parent\):
         wx\.Panel\.\_\_inot\_\_\(self, parent, name="Main, size=\(600,800\)\)

Note that you derived from wx.Frame, but you called the wx.Panel constructor. That's not proper. It IS somewhat common you create a frame and have it contain a panel which then holds all the other objects, but the panel has to be created separately.

import wx
import numpy as np
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure

class MainFrame(wx.Frame):
def __init__(self, parent ):
wx.Frame.__init__(self, parent,name="Main", size = (600,800))
Top = PanelTop(self)
Bottom = PanelBottom(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(Top, 1, wx.EXPAND)

     buttonsizer = wx\.BoxSizer\(wx\.HORIZONTAL\)
     btn1 = wx\.Button\(self, \-1, "Hide top" \)
     btn2 = wx\.Button\(self, \-1, "Hide bottom" \)
     buttonsizer\.AddMany\(\(
         \(\(0,0\), 1, wx\.EXPAND\),
         \(btn1, 0, 0\),
         \(btn2, 0, 0\),
         \(\(0,0\), 1, wx\.EXPAND\),
     \)\)
     sizer\.Add\( buttonsizer, 0, wx\.EXPAND \)
     self\.Bind\( wx\.EVT\_BUTTON, self\.onToggleTop, btn1 \)
     self\.Bind\( wx\.EVT\_BUTTON, self\.onToggleBot, btn2 \)
     self\.top = Top
     self\.bot = Bottom

     sizer\.Add\(Bottom, 1, wx\.EXPAND\)
     self\.SetSizer\(sizer\)

 def onToggleTop\( self, evt \):
     evt\.Skip\(\)
     btn1 = evt\.GetEventObject\(\)
     if self\.top\.IsShown\(\):
         btn1\.SetLabel\( "Hide top" \)
     else:
         btn1\.SetLabel\( "Show top" \)
     self\.top\.Show\( not self\.top\.IsShown\(\) \)

 def onToggleBot\( self, evt \):
     evt\.Skip\(\)
     btn1 = evt\.GetEventObject\(\)
     if self\.bot\.IsShown\(\):
         btn1\.SetLabel\( "Hide bottom" \)
     else:
         btn1\.SetLabel\( "Show bottom" \)
     self\.bot\.Show\( not self\.bot\.IsShown\(\) \)

class PanelTop(wx.Panel):
def __init__(self,parent):
wx.Panel.__init__(self,parent,size = (300,300))
self.SetBackgroundColour('white')
self.figure = Figure(figsize = (4,5))
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self,-1,self.figure)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(self.sizer)

     t = np\.arange\(0\.5, 3\.0, 0\.01\)
     s = np\.cos\(2 \* np\.pi \* t\)
     self\.axes\.plot\(t, s\)

class PanelBottom(wx.Panel):
def __init__(self,parent):
wx.Panel.__init__(self, parent, size = (300,300))
self.SetBackgroundColour('grey77')
self.figure = Figure(figsize = (4,5))
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self,-1,self.figure)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(self.sizer)

     t = np\.arange\(0\.0, 3\.0, 0\.01\)
     s = np\.sin\(2 \* np\.pi \* t\)
     self\.axes\.plot\(t, s\)

app = wx.App(0)
frame = MainFrame(None).Show()
app.MainLoop()

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

hi,

thank you for your help that is good just what i need is to add the button just in PANELTOP not in frame or betwen the two panels just inside PANELTOP it possible to do that ? thank you very much

Majda

Le ven. 24 mai 2019 à 19:25, Tim Roberts timr@probo.com a écrit :

···

Maj wrote:

i need to add hide button in canvas i the same panel how can i do that

how i can have space to add the button ?

i have no idea if is possible to add button in two canvas button ’

plot" like the picture :

Of course it is. You just need to decide where they should go. Here’s a

version of your code with the buttons in between the two panels.

One little comment – you had this in your code:

 class MainFrame(wx.Frame):

     def __init__(*self, parent):

         wx.Panel.__inot__(self, parent, name="Main, size=(600,800))

Note that you derived from wx.Frame, but you called the wx.Panel

constructor. That’s not proper. It IS somewhat common you create a

frame and have it contain a panel which then holds all the other

objects, but the panel has to be created separately.

import wx

import numpy as np

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as

FigureCanvas

from matplotlib.figure import Figure

class MainFrame(wx.Frame):

 def __init__(self, parent ):

     wx.Frame.__init__(self, parent,name="Main", size = (600,800))

     Top = PanelTop(self)

     Bottom = PanelBottom(self)

     sizer = wx.BoxSizer(wx.VERTICAL)

     sizer.Add(Top, 1, wx.EXPAND)



     buttonsizer = wx.BoxSizer(wx.HORIZONTAL)

     btn1 = wx.Button(self, -1, "Hide top" )

     btn2 = wx.Button(self, -1, "Hide bottom" )

     buttonsizer.AddMany((

         ((0,0), 1, wx.EXPAND),

         (btn1, 0, 0),

         (btn2, 0, 0),

         ((0,0), 1, wx.EXPAND),

     ))

     sizer.Add( buttonsizer, 0, wx.EXPAND )

     self.Bind( wx.EVT_BUTTON, self.onToggleTop, btn1 )

     self.Bind( wx.EVT_BUTTON, self.onToggleBot, btn2 )

     self.top = Top

     self.bot = Bottom



     sizer.Add(Bottom, 1, wx.EXPAND)

     self.SetSizer(sizer)



 def onToggleTop( self, evt ):

     evt.Skip()

     btn1 = evt.GetEventObject()

     if self.top.IsShown():

         btn1.SetLabel( "Hide top" )

     else:

         btn1.SetLabel( "Show top" )

     self.top.Show( not self.top.IsShown() )



 def onToggleBot( self, evt ):

     evt.Skip()

     btn1 = evt.GetEventObject()

     if self.bot.IsShown():

         btn1.SetLabel( "Hide bottom" )

     else:

         btn1.SetLabel( "Show bottom" )

     self.bot.Show( not self.bot.IsShown() )

class PanelTop(wx.Panel):

 def __init__(self,parent):

     wx.Panel.__init__(self,parent,size = (300,300))

     self.SetBackgroundColour('white')

     self.figure = Figure(figsize = (4,5))

     self.axes = self.figure.add_subplot(111)

     self.canvas = FigureCanvas(self,-1,self.figure)

     self.sizer = wx.BoxSizer(wx.VERTICAL)

     self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)

     self.SetSizer(self.sizer)



     t = np.arange(0.5, 3.0, 0.01)

     s = np.cos(2 * np.pi * t)

     self.axes.plot(t, s)

class PanelBottom(wx.Panel):

 def __init__(self,parent):

     wx.Panel.__init__(self, parent, size = (300,300))

     self.SetBackgroundColour('grey77')

     self.figure = Figure(figsize = (4,5))

     self.axes = self.figure.add_subplot(111)

     self.canvas = FigureCanvas(self,-1,self.figure)

     self.sizer = wx.BoxSizer(wx.VERTICAL)

     self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)

     self.SetSizer(self.sizer)



     t = np.arange(0.0, 3.0, 0.01)

     s = np.sin(2 * np.pi * t)

     self.axes.plot(t, s)

app = wx.App(0)

frame = MainFrame(None).Show()

app.MainLoop()

Tim Roberts, timr@probo.com

Providenza & Boekelheide, Inc.

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.

To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/1d6e7860-68bc-0b7a-7d06-e5b450d50c2e%40probo.com.

For more options, visit https://groups.google.com/d/optout.

that what i need is just in PANELTOP

Le ven. 24 mai 2019 à 19:25, Tim Roberts timr@probo.com a écrit :

···

Maj wrote:

i need to add hide button in canvas i the same panel how can i do that

how i can have space to add the button ?

i have no idea if is possible to add button in two canvas button ’

plot" like the picture :

Of course it is. You just need to decide where they should go. Here’s a

version of your code with the buttons in between the two panels.

One little comment – you had this in your code:

 class MainFrame(wx.Frame):

     def __init__(*self, parent):

         wx.Panel.__inot__(self, parent, name="Main, size=(600,800))

Note that you derived from wx.Frame, but you called the wx.Panel

constructor. That’s not proper. It IS somewhat common you create a

frame and have it contain a panel which then holds all the other

objects, but the panel has to be created separately.

import wx

import numpy as np

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as

FigureCanvas

from matplotlib.figure import Figure

class MainFrame(wx.Frame):

 def __init__(self, parent ):

     wx.Frame.__init__(self, parent,name="Main", size = (600,800))

     Top = PanelTop(self)

     Bottom = PanelBottom(self)

     sizer = wx.BoxSizer(wx.VERTICAL)

     sizer.Add(Top, 1, wx.EXPAND)



     buttonsizer = wx.BoxSizer(wx.HORIZONTAL)

     btn1 = wx.Button(self, -1, "Hide top" )

     btn2 = wx.Button(self, -1, "Hide bottom" )

     buttonsizer.AddMany((

         ((0,0), 1, wx.EXPAND),

         (btn1, 0, 0),

         (btn2, 0, 0),

         ((0,0), 1, wx.EXPAND),

     ))

     sizer.Add( buttonsizer, 0, wx.EXPAND )

     self.Bind( wx.EVT_BUTTON, self.onToggleTop, btn1 )

     self.Bind( wx.EVT_BUTTON, self.onToggleBot, btn2 )

     self.top = Top

     self.bot = Bottom



     sizer.Add(Bottom, 1, wx.EXPAND)

     self.SetSizer(sizer)



 def onToggleTop( self, evt ):

     evt.Skip()

     btn1 = evt.GetEventObject()

     if self.top.IsShown():

         btn1.SetLabel( "Hide top" )

     else:

         btn1.SetLabel( "Show top" )

     self.top.Show( not self.top.IsShown() )



 def onToggleBot( self, evt ):

     evt.Skip()

     btn1 = evt.GetEventObject()

     if self.bot.IsShown():

         btn1.SetLabel( "Hide bottom" )

     else:

         btn1.SetLabel( "Show bottom" )

     self.bot.Show( not self.bot.IsShown() )

class PanelTop(wx.Panel):

 def __init__(self,parent):

     wx.Panel.__init__(self,parent,size = (300,300))

     self.SetBackgroundColour('white')

     self.figure = Figure(figsize = (4,5))

     self.axes = self.figure.add_subplot(111)

     self.canvas = FigureCanvas(self,-1,self.figure)

     self.sizer = wx.BoxSizer(wx.VERTICAL)

     self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)

     self.SetSizer(self.sizer)



     t = np.arange(0.5, 3.0, 0.01)

     s = np.cos(2 * np.pi * t)

     self.axes.plot(t, s)

class PanelBottom(wx.Panel):

 def __init__(self,parent):

     wx.Panel.__init__(self, parent, size = (300,300))

     self.SetBackgroundColour('grey77')

     self.figure = Figure(figsize = (4,5))

     self.axes = self.figure.add_subplot(111)

     self.canvas = FigureCanvas(self,-1,self.figure)

     self.sizer = wx.BoxSizer(wx.VERTICAL)

     self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)

     self.SetSizer(self.sizer)



     t = np.arange(0.0, 3.0, 0.01)

     s = np.sin(2 * np.pi * t)

     self.axes.plot(t, s)

app = wx.App(0)

frame = MainFrame(None).Show()

app.MainLoop()

Tim Roberts, timr@probo.com

Providenza & Boekelheide, Inc.

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.

To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/1d6e7860-68bc-0b7a-7d06-e5b450d50c2e%40probo.com.

For more options, visit https://groups.google.com/d/optout.

Why would you do that? When you hide PanelTop, the buttons will go way as well. If you need to hide the panels, then I don't think you want the buttons to be part of a panel.

Still, I would hope it is obvious how to make that change.

···

On May 25, 2019, at 2:35 AM, Majda El yacouby <majdaelyacouby1990@gmail.com> wrote:

thank you for your help that is good just what i need is to add the button just in PANELTOP not in frame or betwen the two panels just inside PANELTOP it possible to do that ?


Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

i need to do that cause i have lot of panel in my app when i can’t add button in frame

majda

Le dim. 26 mai 2019 à 08:23, Tim Roberts timr@probo.com a écrit :

···

On May 25, 2019, at 2:35 AM, Majda El yacouby majdaelyacouby1990@gmail.com wrote:

thank you for your help that is good just what i need is to add the button just in PANELTOP not in frame or betwen the two panels just inside PANELTOP it possible to do that ?

Why would you do that? When you hide PanelTop, the buttons will go way as well. If you need to hide the panels, then I don’t think you want the buttons to be part of a panel.

Still, I would hope it is obvious how to make that change.

Tim Roberts, timr@probo.com

Providenza & Boekelheide, Inc.

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.

To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/7E83D044-AEAA-4F1E-9D81-463A4131B8BD%40probo.com.

For more options, visit https://groups.google.com/d/optout.