Pregunta

Me gustaría poder mostrar Notebook y un TxtCtrl wx widgets en un solo marco. A continuación se muestra un ejemplo adaptado de la wxpython wiki; ¿Es posible cambiar su diseño (tal vez con algo como wx.SplitterWindow ) para mostrar el cuadro de texto debajo del Notebook en el mismo marco?

import wx
import wx.lib.sheet as sheet

class MySheet(sheet.CSheet):
    def __init__(self, parent):
        sheet.CSheet.__init__(self, parent)

        self.SetLabelBackgroundColour('#CCFF66')
        self.SetNumberRows(50)
        self.SetNumberCols(50)


class Notebook(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(600, 600))
        menubar = wx.MenuBar()
        file = wx.Menu()
        file.Append(101, 'Quit', '' )
        menubar.Append(file, "&File")
        self.SetMenuBar(menubar)
        wx.EVT_MENU(self, 101, self.OnQuit)
        nb = wx.Notebook(self, -1, style=wx.NB_BOTTOM)
        self.sheet1 = MySheet(nb)
        self.sheet2 = MySheet(nb)
        self.sheet3 = MySheet(nb)
        nb.AddPage(self.sheet1, "Sheet1")
        nb.AddPage(self.sheet2, "Sheet2")
        nb.AddPage(self.sheet3, "Sheet3")
        self.sheet1.SetFocus()
        self.StatusBar()

    def StatusBar(self):
        self.statusbar = self.CreateStatusBar()

    def OnQuit(self, event):
        self.Close()


class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(450, 400))
        self.text = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE)
        self.Center()

class MyApp(wx.App):
    def OnInit(self):
        frame = Notebook(None, -1, 'notebook.py')
        frame.Show(True)
        frame.Center()
        frame2 = MyFrame(None, -1, '')
        frame2.Show(True)
        self.SetTopWindow(frame2)
        return True


app = MyApp(0)
app.MainLoop()
¿Fue útil?

Solución

Hacer que dos widgets aparezcan en el mismo marco es fácil, en realidad. Debes usar los medidores para lograr esto.

En su ejemplo, puede cambiar la implementación de su clase Notebook a algo como esto:

class Notebook(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(600, 600))
        menubar = wx.MenuBar()
        file = wx.Menu()
        file.Append(101, 'Quit', '' )
        menubar.Append(file, "&File")
        self.SetMenuBar(menubar)
        wx.EVT_MENU(self, 101, self.OnQuit)
        nb = wx.Notebook(self, -1, style=wx.NB_BOTTOM)
        self.sheet1 = MySheet(nb)
        self.sheet2 = MySheet(nb)
        self.sheet3 = MySheet(nb)
        nb.AddPage(self.sheet1, "Sheet1")
        nb.AddPage(self.sheet2, "Sheet2")
        nb.AddPage(self.sheet3, "Sheet3")
        self.sheet1.SetFocus()
        self.StatusBar()
        # new code begins here:
        # add your text ctrl:
        self.text = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE)
        # create a new sizer for both controls:
        sizer = wx.BoxSizer(wx.VERTICAL)
        # add notebook first, with size factor 2:
        sizer.Add(nb, 2)
        # then text, size factor 1, maximized
        sizer.Add(self.text, 1, wx.EXPAND)
        # assign the sizer to Frame:
        self.SetSizerAndFit(sizer)

Sólo se cambia el método __init__ . Tenga en cuenta que puede manipular las proporciones entre el cuaderno y el control de texto cambiando el segundo argumento del método Add .

Puede obtener más información sobre los tamaños en el descripción general del Sizer .

Otros consejos

Puedes usar un divisor, sí.

Además, tiene sentido crear un Panel, colocar los widgets en él (con los tamaños) y agregar este panel al Marco.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top