Maybe the topic should be how to put background colors to sizers, but anyway...
could anyone please help me, I need to have "background color for buttons", like in example blue & red, and then using sizers to center buttons... this task would be so easier if only I could set background color for boxsizer =p
so please try to center these buttons with sizers without removing red&blue background
[code=python]
import wx
class MyFrame(wx.Fram e):
def __init__(self):
wx.Frame.__init __(self, None, id=-1, size=(300,150))
frame_panel = wx.Panel(self, -1)
button1_panel = wx.Panel(frame_ panel, -1) #panel for button1
button1_panel.S etBackgroundCol our('BLUE')
button2_panel = wx.Panel(frame_ panel, -1) #panel for button2
button2_panel.S etBackgroundCol our('RED')
button1 = wx.Button(butto n1_panel, id=-1, label="button1" , size=(80,20))
button2 = wx.Button(butto n2_panel, id=-1, label="button2" , size=(80,20))
button1_sizer = wx.BoxSizer(wx. HORIZONTAL) #add button1 to sizer
button1_sizer.A dd(button1, 0, wx.ALIGN_CENTER )
button2_sizer = wx.BoxSizer(wx. HORIZONTAL) #add button2 to sizer
button2_sizer.A dd(button1, 0, wx.ALIGN_CENTER )
button1_panel.S etSizer(button1 _sizer) #set sizers for panel
button2_panel.S etSizer(button2 _sizer)
hbox = wx.BoxSizer(wx. HORIZONTAL) #add panels to "main sizer"
hbox.Add(button 1_panel, 1, wx.EXPAND|wx.AL IGN_CENTER_HORI ZONTAL)
hbox.Add(button 2_panel, 1, wx.EXPAND|wx.AL IGN_CENTER_HORI ZONTAL)
frame_panel.Set AutoLayout(True )
frame_panel.Set Sizer(hbox)
frame_panel.Lay out()
app = wx.PySimpleApp( )
MyFrame().Show( )
app.MainLoop()
[/code]
If you want to start from "beginning" , here's the code without background colors, just insert here those colors like in first example (and use sizers)
[code=python]
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import wx
class MyFrame(wx.Fram e):
def __init__(self):
wx.Frame.__init __(self, None, id=-1, size=(300,150))
frame_panel = wx.Panel(self, -1)
button1 = wx.Button(frame _panel, id=-1, label="button1" , size=(80,20))
button2 = wx.Button(frame _panel, id=-1, label="button2" , size=(80,20))
hbox = wx.BoxSizer(wx. HORIZONTAL)
hbox.Add(button 1, 1, wx.ALIGN_CENTER |wx.ALL, 25)
hbox.Add(button 2, 1, wx.ALIGN_CENTER |wx.ALL, 25)
frame_panel.Set AutoLayout(True )
frame_panel.Set Sizer(hbox)
frame_panel.Lay out()
app = wx.PySimpleApp( )
MyFrame().Show( )
app.MainLoop()
[/code]
could anyone please help me, I need to have "background color for buttons", like in example blue & red, and then using sizers to center buttons... this task would be so easier if only I could set background color for boxsizer =p
so please try to center these buttons with sizers without removing red&blue background
[code=python]
import wx
class MyFrame(wx.Fram e):
def __init__(self):
wx.Frame.__init __(self, None, id=-1, size=(300,150))
frame_panel = wx.Panel(self, -1)
button1_panel = wx.Panel(frame_ panel, -1) #panel for button1
button1_panel.S etBackgroundCol our('BLUE')
button2_panel = wx.Panel(frame_ panel, -1) #panel for button2
button2_panel.S etBackgroundCol our('RED')
button1 = wx.Button(butto n1_panel, id=-1, label="button1" , size=(80,20))
button2 = wx.Button(butto n2_panel, id=-1, label="button2" , size=(80,20))
button1_sizer = wx.BoxSizer(wx. HORIZONTAL) #add button1 to sizer
button1_sizer.A dd(button1, 0, wx.ALIGN_CENTER )
button2_sizer = wx.BoxSizer(wx. HORIZONTAL) #add button2 to sizer
button2_sizer.A dd(button1, 0, wx.ALIGN_CENTER )
button1_panel.S etSizer(button1 _sizer) #set sizers for panel
button2_panel.S etSizer(button2 _sizer)
hbox = wx.BoxSizer(wx. HORIZONTAL) #add panels to "main sizer"
hbox.Add(button 1_panel, 1, wx.EXPAND|wx.AL IGN_CENTER_HORI ZONTAL)
hbox.Add(button 2_panel, 1, wx.EXPAND|wx.AL IGN_CENTER_HORI ZONTAL)
frame_panel.Set AutoLayout(True )
frame_panel.Set Sizer(hbox)
frame_panel.Lay out()
app = wx.PySimpleApp( )
MyFrame().Show( )
app.MainLoop()
[/code]
If you want to start from "beginning" , here's the code without background colors, just insert here those colors like in first example (and use sizers)
[code=python]
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import wx
class MyFrame(wx.Fram e):
def __init__(self):
wx.Frame.__init __(self, None, id=-1, size=(300,150))
frame_panel = wx.Panel(self, -1)
button1 = wx.Button(frame _panel, id=-1, label="button1" , size=(80,20))
button2 = wx.Button(frame _panel, id=-1, label="button2" , size=(80,20))
hbox = wx.BoxSizer(wx. HORIZONTAL)
hbox.Add(button 1, 1, wx.ALIGN_CENTER |wx.ALL, 25)
hbox.Add(button 2, 1, wx.ALIGN_CENTER |wx.ALL, 25)
frame_panel.Set AutoLayout(True )
frame_panel.Set Sizer(hbox)
frame_panel.Lay out()
app = wx.PySimpleApp( )
MyFrame().Show( )
app.MainLoop()
[/code]
Comment