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,
ti...@probo.com
Providenza & Boekelheide, Inc.