How to fit widgets inside a wx.Dialog such that it takes up the entire space

I am creating a GUI application where the user clicks something and a dialog appears. The dialog that appears is dynamic in nature as the number of widgets in the dialog depends on the button which the user clicks. I have attached a sample code for a specific case. The problem I am having is that I am not able to exactly fit everything in the Dialog. What I want is that the widgets inside should take all the space and the dialog resizes according to the number and size of widgets inside it. I have spent a long time on it but I am not able to do it. Please help me. I have attached the code below also :

import wx

class InputDialog(wx.Dialog):

def init(self):

super(InputDialog, self).init(None, title=‘Dialog Box’)

self.InitUI()

def InitUI(self):

Create Panel

pnl = wx.Panel(self)

vbox = wx.BoxSizer(wx.VERTICAL)

sbs = wx.BoxSizer(wx.VERTICAL)

params = [ [‘diameter’, 1.0, ‘mm’],

[‘radius’, 1.0, ‘mm’],

[‘k’, 1.0, ‘mm’],

[‘terms’, [], ‘’],

[‘ctrHeight’, 0.0, ‘’],

[‘position’, [0.0,0.0,0.0], ‘mm’],

[‘rotation’, [0.0,0.0,0.0], ‘deg’] ]

Add Parameters

self.params = []

for param in params:

box = wx.BoxSizer(wx.HORIZONTAL)

if isinstance(param[2], str):

self.params.append(wx.TextCtrl(pnl, value="%s" % param[1]))

box.Add(wx.StaticText(pnl,wx.ID_ANY, label="%s: " % param[0]))

box.Add(self.params[len(self.params)-1], flag=wx.LEFT, border=3)

box.Add(wx.StaticText(pnl,wx.ID_ANY, label=" %s" % param[2]))

else:

self.params.append(wx.ListBox(pnl, -1, wx.DefaultPosition, (170, 110), param[2]))

self.params[len(self.params)-1].SetSelection(param[1])

box.Add(wx.StaticText(pnl,wx.ID_ANY, label="%s: " % param[0]))

box.Add(self.params[len(self.params)-1], flag=wx.LEFT, border=3)

sbs.AddSpacer(10,10)

sbs.Add(box)

pnl.SetSizer(sbs)

hbox3 = wx.BoxSizer(wx.HORIZONTAL)

okButton = wx.Button(self, label=‘Ok’)

okButton.Bind(wx.EVT_BUTTON, self.OnOk)

hbox3.Add(okButton)

closeButton = wx.Button(self, label=‘Cancel’)

closeButton.Bind(wx.EVT_BUTTON, self.OnCancel)

hbox3.Add(closeButton, flag=wx.LEFT, border=5)

vbox.Add(pnl, proportion=1,flag=wx.ALL|wx.EXPAND, border=5)

vbox.Add(hbox3,flag=wx.ALIGN_CENTER|wx.TOP|wx.BOTTOM, border=10)

self.SetSizer(vbox)

def OnOk(self, e):

self.accept = 1

self.Destroy()

def OnCancel(self, e):

self.accept = 0

self.Destroy()

if name == ‘main’:

app = wx.PySimpleApp()

dlg = InputDialog()

try:

dlg.ShowModal()

finally:

dlg.Destroy()

app.MainLoop()

question.py (2.32 KB)

You want to:

Not set a size for the dialog

Call self.SetSizerAndFit(the_sizer)

This could make a big dialog if you have a lot of widgets on it, but if that’s under your control, you should be good.

If it could be virtually any size, then you could put a wxScrolledWindow on it.

-Chris

···

On Thu, Apr 3, 2014 at 12:57 PM, Samyak Jain samyak.iitk@gmail.com wrote:

I am creating a GUI application where the user clicks something and a dialog appears. The dialog that appears is dynamic in nature as the number of widgets in the dialog depends on the button which the user clicks. I have attached a sample code for a specific case. The problem I am having is that I am not able to exactly fit everything in the Dialog. What I want is that the widgets inside should take all the space and the dialog resizes according to the number and size of widgets inside it. I have spent a long time on it but I am not able to do it. Please help me. I have attached the code below also :

import wx

class InputDialog(wx.Dialog):

def init(self):

super(InputDialog, self).init(None, title=‘Dialog Box’)

self.InitUI()

def InitUI(self):

Create Panel

pnl = wx.Panel(self)

vbox = wx.BoxSizer(wx.VERTICAL)

sbs = wx.BoxSizer(wx.VERTICAL)

params = [ [‘diameter’, 1.0, ‘mm’],

[‘radius’, 1.0, ‘mm’],

[‘k’, 1.0, ‘mm’],

[‘terms’, , ‘’],

[‘ctrHeight’, 0.0, ‘’],

[‘position’, [0.0,0.0,0.0], ‘mm’],

[‘rotation’, [0.0,0.0,0.0], ‘deg’] ]

Add Parameters

self.params =

for param in params:

box = wx.BoxSizer(wx.HORIZONTAL)

if isinstance(param[2], str):

self.params.append(wx.TextCtrl(pnl, value=“%s” % param[1]))

box.Add(wx.StaticText(pnl,wx.ID_ANY, label="%s: " % param[0]))

box.Add(self.params[len(self.params)-1], flag=wx.LEFT, border=3)

box.Add(wx.StaticText(pnl,wx.ID_ANY, label=" %s" % param[2]))

else:

self.params.append(wx.ListBox(pnl, -1, wx.DefaultPosition, (170, 110), param[2]))

self.params[len(self.params)-1].SetSelection(param[1])

box.Add(wx.StaticText(pnl,wx.ID_ANY, label="%s: " % param[0]))

box.Add(self.params[len(self.params)-1], flag=wx.LEFT, border=3)

sbs.AddSpacer(10,10)

sbs.Add(box)

pnl.SetSizer(sbs)

hbox3 = wx.BoxSizer(wx.HORIZONTAL)

okButton = wx.Button(self, label=‘Ok’)

okButton.Bind(wx.EVT_BUTTON, self.OnOk)

hbox3.Add(okButton)

closeButton = wx.Button(self, label=‘Cancel’)

closeButton.Bind(wx.EVT_BUTTON, self.OnCancel)

hbox3.Add(closeButton, flag=wx.LEFT, border=5)

vbox.Add(pnl, proportion=1,flag=wx.ALL|wx.EXPAND, border=5)

vbox.Add(hbox3,flag=wx.ALIGN_CENTER|wx.TOP|wx.BOTTOM, border=10)

self.SetSizer(vbox)

def OnOk(self, e):

self.accept = 1

self.Destroy()

def OnCancel(self, e):

self.accept = 0

self.Destroy()

if name == ‘main’:

app = wx.PySimpleApp()

dlg = InputDialog()

try:

dlg.ShowModal()

finally:

dlg.Destroy()

app.MainLoop()

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax

Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov