| | |
Changing control sizes at run-time
Thread Solved |
•
•
Join Date: Feb 2007
Posts: 3
Reputation:
Solved Threads: 0
Hello,
I have a simple script with 2 buttons positioned vertically within a sizer on a panel.
A button-click event attached to the top button changes the height of the top button. However, even though the height of the top button changes, the height of the bottom button does not automatically resize to accomodate the new height of the top button.
Adding
How can I change the height of the top button and automatically resize the height of the bottom button?
[php]
#!/usr/bin/python
import wx
class AFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.SetSize(wx.Size(300,400))
self.panel = wx.Panel(self)
self.button1 = wx.Button(self.panel, 1000, "Button1")
self.button1.Bind(wx.EVT_BUTTON, self.BtnClick)
self.button2 = wx.Button(self.panel, 1001, "Button2")
self.myboxsizer = wx.BoxSizer(wx.VERTICAL)
self.myboxsizer.Add(self.button1,0,wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT,30)
self.myboxsizer.Add(self.button2,1,wx.EXPAND|wx.ALL,30)
self.panel.SetSizer(self.myboxsizer)
def BtnClick(self,event):
self.button1.SetSize(wx.Size(-1,80))
#self.myboxsizer.Layout()
if __name__ == '__main__':
app = wx.App()
daframe = AFrame(None)
daframe.Show()
app.MainLoop()
[/php]
Any assistance will be appreciated. Thank you.
I have a simple script with 2 buttons positioned vertically within a sizer on a panel.
A button-click event attached to the top button changes the height of the top button. However, even though the height of the top button changes, the height of the bottom button does not automatically resize to accomodate the new height of the top button.
Adding
self.myboxsizer.Layout() after I change the height of the button does not change the height of the bottom button, but only serves to revert the height of the top button to its original (unmodified) height.How can I change the height of the top button and automatically resize the height of the bottom button?
[php]
#!/usr/bin/python
import wx
class AFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.SetSize(wx.Size(300,400))
self.panel = wx.Panel(self)
self.button1 = wx.Button(self.panel, 1000, "Button1")
self.button1.Bind(wx.EVT_BUTTON, self.BtnClick)
self.button2 = wx.Button(self.panel, 1001, "Button2")
self.myboxsizer = wx.BoxSizer(wx.VERTICAL)
self.myboxsizer.Add(self.button1,0,wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT,30)
self.myboxsizer.Add(self.button2,1,wx.EXPAND|wx.ALL,30)
self.panel.SetSizer(self.myboxsizer)
def BtnClick(self,event):
self.button1.SetSize(wx.Size(-1,80))
#self.myboxsizer.Layout()
if __name__ == '__main__':
app = wx.App()
daframe = AFrame(None)
daframe.Show()
app.MainLoop()
[/php]
Any assistance will be appreciated. Thank you.
•
•
Join Date: Feb 2007
Posts: 3
Reputation:
Solved Threads: 0
Solution discovered with a little help from friends on another post ...
You need to set the minimum size of the button so that the buttons are rendered with the desired dimensions by the controlling sizer on linux:
[php] def BtnClick(self,event):
newsize = wx.Size(-1,80)
self.button1.SetMinSize(newsize)
self.button1.SetSize(newsize)
self.myboxsizer.Layout()
[/php]
The above displays the buttons correctly on fc6.
You need to set the minimum size of the button so that the buttons are rendered with the desired dimensions by the controlling sizer on linux:
[php] def BtnClick(self,event):
newsize = wx.Size(-1,80)
self.button1.SetMinSize(newsize)
self.button1.SetSize(newsize)
self.myboxsizer.Layout()
[/php]
The above displays the buttons correctly on fc6.
Last edited by Acolyte; Feb 17th, 2007 at 7:33 am.
![]() |
Similar Threads
- Run-time error '5' (Windows NT / 2000 / XP)
- Dynamically changing a form at Run Time (VB.NET)
- Heap problem at run time (C++)
- "Run time error, do you wish to debug?" (Web Browsers)
- Run-Time Error..? (Windows NT / 2000 / XP)
Other Threads in the Python Forum
- Previous Thread: Pygame
- Next Thread: Transparent letters in Tkinter?
| Thread Tools | Search this Thread |
accessdenied advanced aliased argv beginner bits calling casino change command convert count csv cturtle cursor def dictionary digital dynamic dynamically enter event examples external file float format frange function google gui hints homework i/o iframe import input jaunty java keyboard lapse line linux list lists loop microphone mouse movingimageswithpygame multiple newb number numbers obexftp output parameters parsing path port prime programming projects py py2exe pygame pygtk pyopengl python random recursion remote return reverse scrolledtext session signal simple skinning sprite string strings syntax terminal text threading time tkinter tlapse tuple tutorial ubuntu unicode unit urllib urllib2 variable voip web-scrape whileloop wxpython






