1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #! /usr/bin/env python
#-*- coding: utf-8 -*-
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, title = "Switch button")
self.panel = wx.Panel(self, -1)
self.bouton = None
self.sizerPanel = wx.BoxSizer(wx.HORIZONTAL)
self.panelGauche = wx.Panel(self.panel, -1)
self.panelGauche.SetBackgroundColour(wx.BLUE)
self.panelDroit = wx.Panel(self.panel, -1)
self.panelDroit.SetBackgroundColour(wx.RED)
self.szGauche = wx.BoxSizer(wx.VERTICAL)
self.panelGauche.SetSizer(self.szGauche)
self.szDroit = wx.BoxSizer(wx.VERTICAL)
self.panelDroit.SetSizer(self.szDroit)
self.sizerPanel.Add(self.panelGauche, 1, wx.EXPAND)
self.sizerPanel.Add(self.panelDroit, 1, wx.EXPAND)
self.panel.SetSizer(self.sizerPanel)
titre = "Basculer -->"
self.bouton = wx.Button(self.panelGauche, -1, titre)
self.szGauche.AddStretchSpacer()
self.szGauche.Add(self.bouton, 0, wx.ALIGN_CENTER|wx.ALL, 20)
self.szGauche.AddStretchSpacer()
self.panelGauche.Layout()
self.position = 0
self.panel.Fit()
self.Fit()
self.Bind(wx.EVT_BUTTON, self.Basculer, self.bouton)
def Basculer(self, event):
if self.position == 0:
self.sizerPanel.Remove(self.panelGauche)
self.sizerPanel.Remove(self.panelDroit)
self.bouton.SetLabel("<-- Basculer")
self.sizerPanel.Add(self.panelDroit, 1, wx.EXPAND)
self.sizerPanel.Add(self.panelGauche, 1, wx.EXPAND)
self.sizerPanel.Layout()
self.position = 1
else:
self.sizerPanel.Remove(self.panelDroit)
self.sizerPanel.Remove(self.panelGauche)
self.bouton.SetLabel("Basculer -->")
self.sizerPanel.Add(self.panelGauche, 1, wx.EXPAND)
self.sizerPanel.Add(self.panelDroit, 1, wx.EXPAND)
self.sizerPanel.Layout()
self.position = 0
self.Refresh()
class MyApp(wx.App):
def OnInit(self):
f = MyFrame()
f.Show(True)
self.SetTopWindow(f)
return True
app = MyApp()
app.MainLoop() |