Resizable Tabbed (wxNotebook) Dialog

Jose M. Balaguer jbalague at yahoo.com
Fri Aug 16 12:20:26 CEST 2002


This is an example of using a Tabbed (wxNotebook) Dialog with
resizable controls. (It took me more than 2 days to realize I had to
use wxPanel instead of wxWindows controls)

Hope it helps someone... 
-- jbalague 


*********************** BEGIN ***********************
from wxPython.wx import *

#----------------------------------------------------------------------
class MyTabbedDlg(wxDialog):
  def __init__(self, parent):
    title = "Resize the dialog and see how controls adapt!"
    wxDialog.__init__(self, parent, -1, title, style=wxRESIZE_BORDER)

    notebook = wxNotebook(self, -1, size=(450,300))
    panel1 = wxPanel(notebook, -1, style = wxNO_BORDER)
    panel2 = wxPanel(notebook, -1, style = wxNO_BORDER)
    notebook.AddPage(panel1, "Panel 1")
    notebook.AddPage(panel2, "Panel 2")

    dialog_sizer = wxBoxSizer(wxVERTICAL)
    dialog_sizer.Add(notebook, 1, wxEXPAND|wxALL, 5)

    panel1_sizer = wxBoxSizer(wxVERTICAL)
    text = wxTextCtrl(panel1, -1, "Hi!", size=(400,90),
style=wxTE_MULTILINE)
    button1 = wxButton(panel1, -1, "I only resize horizontally...")
    panel1_sizer.Add(text, 1, wxEXPAND|wxALL, 10)
    panel1_sizer.Add(button1, 0, wxEXPAND|wxALL, 10)
    panel1.SetSizer(panel1_sizer)
    panel1.SetAutoLayout(true)

    panel2_sizer = wxBoxSizer(wxHORIZONTAL)
    button2 = wxButton(panel2, -1, "I resize vertically")
    button3 = wxButton(panel2, -1, "I don't like resizing!")
    panel2_sizer.Add(button2, 0, wxEXPAND|wxALL, 20)
    panel2_sizer.Add(button3, 0, wxALL, 100)
    panel2.SetSizer(panel2_sizer)
    panel2.SetAutoLayout(true)

    self.SetSizer(dialog_sizer)
    self.SetAutoLayout(true)
    self.Fit()
    self.Centre()

#----------------------------------------------------------------------
class MyApp(wxApp):
  def OnInit(self):
    frame = wxFrame(NULL, -1, 'Tabbed/wxNotebook Dialog with resizable
controls')
    frame.Show(true)
    dlg = MyTabbedDlg(frame)
    dlg.ShowModal()
    dlg.Destroy()
    frame.Close()
    return true

myapp = MyApp(0)
myapp.MainLoop()
*********************** END ***********************



More information about the Python-list mailing list