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 -
import wx
-
-
class MyFrame(wx.Frame):
-
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.SetBackgroundColour('BLUE')
-
-
button2_panel = wx.Panel(frame_panel, -1) #panel for button2
-
button2_panel.SetBackgroundColour('RED')
-
-
button1 = wx.Button(button1_panel, id=-1, label="button1", size=(80,20))
-
button2 = wx.Button(button2_panel, id=-1, label="button2", size=(80,20))
-
-
button1_sizer = wx.BoxSizer(wx.HORIZONTAL) #add button1 to sizer
-
button1_sizer.Add(button1, 0, wx.ALIGN_CENTER)
-
button2_sizer = wx.BoxSizer(wx.HORIZONTAL) #add button2 to sizer
-
button2_sizer.Add(button1, 0, wx.ALIGN_CENTER)
-
-
button1_panel.SetSizer(button1_sizer) #set sizers for panel
-
button2_panel.SetSizer(button2_sizer)
-
-
hbox = wx.BoxSizer(wx.HORIZONTAL) #add panels to "main sizer"
-
hbox.Add(button1_panel, 1, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL)
-
hbox.Add(button2_panel, 1, wx.EXPAND|wx.ALIGN_CENTER_HORIZONTAL)
-
-
frame_panel.SetAutoLayout(True)
-
frame_panel.SetSizer(hbox)
-
frame_panel.Layout()
-
-
app = wx.PySimpleApp()
-
MyFrame().Show()
-
app.MainLoop()
-
-
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) -
#!/usr/bin/env python
-
# -*- coding: UTF-8 -*-
-
-
import wx
-
-
class MyFrame(wx.Frame):
-
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(button1, 1, wx.ALIGN_CENTER|wx.ALL, 25)
-
hbox.Add(button2, 1, wx.ALIGN_CENTER|wx.ALL, 25)
-
-
frame_panel.SetAutoLayout(True)
-
frame_panel.SetSizer(hbox)
-
frame_panel.Layout()
-
-
app = wx.PySimpleApp()
-
MyFrame().Show()
-
app.MainLoop()
-
1 6891
I noticed you have the sizer set on the panel named frame_panel. What if the frame had two panels, frame_panel_1 and frame_panel_2, each panel with one button?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Miki Tebeka |
last post by:
Hello All,
I have a frame that contains a panel and several buttons.
I'd like to make one of the button the default button but
self.SetDefaultItem(btn) or btn.SetFocus() don't work. The item in
focus is a text control inside the panel.
Any Ideas? (see short example below)
Thanks.
|
by: Grant Edwards |
last post by:
Can anybody recommend a good book on wxPython? Are there any
books on wxPython?
I've been trying to learn wxPython and/or wax for a few weeks,
and I'm just not getting it.
wxWindows seems to be more low-level than the other GUI
toolkits I've used (Tk, GTK, and Trestle), and there are all
sorts exposed details in wxWindows/wxPython...
|
by: mdk.R |
last post by:
Hello all:
i'am installed wxPython 2.5 and Python2.3.4..i try execute script
with wxPython but it show error:
Traceback (most recent call last):
File "E:\py\test.py", line 7, in ?
import wx
File "E:\py\wx.py", line 10, in ?
from wxPython.wx import *
File "D:\Python23\Lib\site-package
import _wx
|
by: John Salerno |
last post by:
I was reading in the wxPython wiki that most of the time you don't have
to include the id parameter at all, and you can just use keyword
arguments for other parameters. But I'm having trouble converting this
code into that method (i.e., without the id parameter). I keep getting
errors that involve wrong parameters, or that they are out of...
|
by: Grant |
last post by:
Hi, I am looking for a tip. I have a panel and a checkbox. When I
check the checkbox, I would like to add buttons to the panel
(dynamically). When the checkbox is unchecked, the buttons should not
appear (be deleted)---all the while, the window should resize if necessary.
If you have a simpler example, that is fine. I just need a hint as...
| |
by: Tyler |
last post by:
Hello All:
I am currently working on a project to create an FEM model for school.
I was thinking about using wxPython to gather the 12 input variables
from the user, then, after pressing the "Run" button, the GUI would
close, and the 12 input variables would then be available for the rest
of the program.
So far, what I have been able to...
|
by: Soren |
last post by:
Hi,
I'm trying to create a small GUI program where I can do plots using
Matplotlib. I've been trying to borrow code from the examples at the
matplotlib website, but I can't get it to work.
I want to be able to create a wx.Panel that contains an axis for
plotting. Around it i want other panels containing various settings,
buttons etc. to...
|
by: Soren |
last post by:
Hi,
I've been trying to embed matplotlib in wxpython. I want to be able to
put a figure (axes) in a wx.Panel and place it somewhere in my GUI.
The GUI should have other panels with buttons etc. that can control
the output on the figure. I've been looking at the examples from the
matplotlib website, but can't seem to get it to work..
Does...
|
by: Soren |
last post by:
Hi,
Id like to make my own special listbox.. I want to able (at the push
of a button) to add another item to my special listbox... each item is
a panel with a label, some buttons and maybe a text control.
I've tried adding a new panel object with the stuff i want to the
sizer i'm using for my listbox (which is a panel which can contain...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |