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)