473,661 Members | 2,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxPython, dynamically modify window

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 to
how you dynamically change the widgets and their layouts.

Looking at the wx demos, there is something close wx.lib.expando, but
this is just modifying a particular widget.

Thanks.
Dec 12 '06 #1
1 6073

Grant wrote:
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.
Here is one way that seems to work (wxPython 2.7, Python 2.5, Mac OS X
10.4.8). It uses a sizer's Hide() and Show() methods to control
visibility of a child sizer containing the buttons. To resize the frame
containing the checkbox and buttons, ensure the frame has a sizer and
use the Fit() method after Hiding and Showing the buttons.
HTH,
-- CMcP

import wx

class AppFrame(wx.Fra me):
def __init__(self, parent, title):
wx.Frame.__init __(self, parent, -1, title)
panel = wx.Panel(self, -1)
panel_sizer = wx.BoxSizer(wx. VERTICAL)
panel.SetSizer( panel_sizer)

cb = wx.CheckBox(pan el, -1, 'Need some buttons')
cb.SetValue(Fal se)
self.Bind(wx.EV T_CHECKBOX, self.EvtCheckBo x, cb)

button_sizer = wx.BoxSizer(wx. HORIZONTAL)
b1 = wx.Button(panel , -1, 'Button 1')
b2 = wx.Button(panel , -1, 'Button 2')
button_sizer.Ad d(b1, 0, wx.ALL, 5)
button_sizer.Ad d(b2, 0, wx.ALL, 5)

panel_sizer.Add (cb, 0, wx.ALL, 5)
panel_sizer.Add (button_sizer)

panel_sizer.Hid e(button_sizer, recursive=True)

frame_sizer = wx.BoxSizer()
frame_sizer.Add (panel, 1, wx.EXPAND)

self.SetSizer(f rame_sizer)
self.panel_size r = panel_sizer
self.button_siz er = button_sizer

self.Fit()

def EvtCheckBox(sel f, event):
cb = event.GetEventO bject()
if cb.GetValue() == True:
self.panel_size r.Show(self.but ton_sizer, recursive=True)
else:
self.panel_size r.Hide(self.but ton_sizer, recursive=True)
self.Fit()

class App(wx.App):
def OnInit(self):
frame = AppFrame(None, 'Hide/Show Example')
self.SetTopWind ow(frame)
frame.Show()
return True

if __name__ == '__main__':
app = App()
app.MainLoop()

Dec 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2193
by: Logan | last post by:
Would you recommend to use the wx package of wxPython? From the documentation: Provides a way to drop the wx prefix from wxPython objects by dynamically loading and renaming objects from the real wxPython package. This is the first phase of a transition to a new style of using wxPython. For example: import wx
9
3188
by: Rick Muller | last post by:
I have a problem that I would like to get some advice on from other Pythonistas. I currently manage a (soon to be) open source project for displaying molecular graphics for a variety of different programs. To do this I need to draw pictures of the molecules, typically using OpenGL, and do some basic control, using some widget set. The code currently uses GTK, and runs on Macintosh OS X under Fink, and Linux. I would like to support the...
0
1954
by: Richard Townsend | last post by:
I've been experimenting with passing a window handle from a wxPython app to a Tkinter app. The Tkinter app should embed a Toplevel window containing a Canvas widget in the wxPython app's Frame (see example below). Both apps run, but the Tkinter app's output doesn't appear. Can anyone see why this isn't working? Using wxPython-2.5.1/Python 2.3.3/Win98 and Win2000.
0
1654
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this version, many of which are listed below and at http://wxpython.org/recentchanges.php. What is wxPython?
0
1532
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this version, many of which are listed below and at http://wxpython.org/recentchanges.php. What is wxPython?
4
2976
by: stef | last post by:
hello, I'm trying to move from Delphi to Python (move from MatLab to Python already succeeded, also thanks to this discussion group). From the discussions in this list about "the best" GUI for Python, it now seems to me that wxPython is thé choice for my kind of applications. I've no experience with wxPython yet, I just run a few examples and indeed it looks good (as expected from the
44
4981
by: bg_ie | last post by:
Hi, I'm in the process of writing some code and noticed a strange problem while doing so. I'm working with PythonWin 210 built for Python 2.5. I noticed the problem for the last py file processed by this script, where the concerned tmp file is only actually written to when PythonWin is closed. In other words, after I run this script, one of the generated tmp files has a size of 0kB. I then close PythonWin and it is then written to.
16
2394
by: Andrea Gavana | last post by:
Hi Diez & All, Do you mind explaining "why" you find it *buttugly*? I am asking just out of curiosity, obviously. I am so biased towards wxPython that I won't make any comment on this thread in particular, but I am curious to know why some people find it "ugly" or "bad" or whatever. It has its own bugs and missing features, of course, but it is one of the major GUI player in the arena, together with PyQt and PyGTK.
0
1800
by: Guilherme Polo | last post by:
On 10/29/08, Olrik Lenstra <o.lenstra@gmail.comwrote: It will be a combination of commands, not a single one. Initially I considered this as "probably without solution", since tcl acquired a yield command just in the 8.6a3 release, but then I looked at wx.SafeYield code and apparently it is possible to replicate it. Here is an initial cut, it is very possible to contain something not equivalent to wx.SafeYield (besides it could be...
0
8343
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8855
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7364
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
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
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.