It seems like a simple problem but I can't seem to find the solution. Basically I have a wx.TextCtrl on a wx.ScrolledWindow and I want to expand the TextCtrl to fill the window - a simple editor if you will.
I have the "Proportion" as "1" and I've used a sizer and tried different "Layouts" but nothing works.
Not only that but I want to expand scroll bars at will and see the whole rectangle change at will. MS-Notepad does exactly what I want it to do. The code is below. (13 lines) Any ideas?
RR

import wx

class ScrollbarFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'Scrollbar Example', 
                size=(300, 200))
        sizer = wx.BoxSizer()
        self.scroll  = wx.ScrolledWindow(self, -1)
        self.scroll.SetScrollbars(1, 1, 1000, 1000)
        self.scratch = wx.TextCtrl(self.scroll, -1, style=wx.TE_MULTILINE|wx.ALL|wx.TE_RICH2)
    sizer.Add(self.scratch, 1, wx.ALL|wx.EXPAND|wx.ALIGN_RIGHT|wx.ADJUST_MINSIZE, 0)
    self.scratch.SetEditable(True)
        self.SetBackgroundColour(wx.WHITE)  # Sets canvas to WHITE (from grey)
        self.scratch.SetFocus()


        #self.SetAutoLayout(True)        #  None of these seemed to work as I'd hoped
        #self.SetSizer(sizer_1)   
        #sizer_1.Fit(self)           
        #sizer_1.SetSizeHints(self)  
        #self.Fit()
        #self.Layout()



if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = ScrollbarFrame()
    frame.Show()
    app.MainLoop()

Hello robinlrandall,
Here is a simple notepad program I wrote a while back in wxPython. If you have any questions on it I would be happy to answer them.

  • WolfShield

    import wx

    class Notepad(wx.Frame):

    def __init__(self, *args, **kwargs):
        super(Notepad, self).__init__(*args, **kwargs)
    
        self.InitUI()
    
    def InitUI(self):
    
        menubar = wx.MenuBar()
    
        fileMenu = wx.Menu()
        fileNew = fileMenu.Append(wx.ID_NEW, 'New', 'New document')
        fileOpen = fileMenu.Append(wx.ID_OPEN, 'Open', 'Open a saved document')
        fileSave = fileMenu.Append(wx.ID_SAVE, 'Save', 'Save this document to hard drive')
        fileSaveAs = fileMenu.Append(wx.ID_SAVEAS, 'Save As', 'Save this document under a new name')
        fileMenu.AppendSeparator()
        fileExit = fileMenu.Append(wx.ID_EXIT, 'Exit', 'Exit application')
    
        editMenu = wx.Menu()
        editCut = editMenu.Append(wx.ID_CUT, 'Cut', 'Cut selected text')
        editCopy = editMenu.Append(wx.ID_COPY, 'Copy', 'Copy selected text')
        editPaste = editMenu.Append(wx.ID_PASTE, 'Paste', 'Paste selection from clipboard')
    
        helpMenu = wx.Menu()
        helpAbout = helpMenu.Append(wx.ID_ABOUT, 'About', 'About PyPad')
        helpHelp = helpMenu.Append(wx.ID_HELP, 'Help File', 'The Help File')
    
        menubar.Append(fileMenu, '&File')
        menubar.Append(editMenu, '&Edit')
        menubar.Append(helpMenu, '&Help')
        self.SetMenuBar(menubar)
    
        self.Bind(wx.EVT_MENU, self.OnNew, fileNew)
        self.Bind(wx.EVT_MENU, self.OnExit, fileExit)
        self.Bind(wx.EVT_MENU, self.OnCut, editCut)
        self.Bind(wx.EVT_MENU, self.OnCopy, editCopy)
        self.Bind(wx.EVT_MENU, self.OnPaste, editPaste)
    
        self.text = wx.TextCtrl(self, 1000, size=(-1, -1), style=wx.TE_MULTILINE | wx.TE_PROCESS_ENTER)
    
        self.SetSize((300, 200))
        self.SetTitle('PyPad v0.1')
        self.CreateStatusBar()
        self.Centre()
        self.Show(True)
    
    def OnNew(self, e):
        self.text.Clear()
    
    def OnExit(self, e):
        self.Close()
    
    def OnCut(self, e):
        self.text.Cut()
    
    def OnCopy(self, e):
        self.text.Copy()
    
    def OnPaste(self, e):
        self.text.Paste()
    

    def main():

    ex = wx.App()
    Notepad(None)
    ex.MainLoop()
    

    if name == 'main':
    main()

Thanks. The scrolled Window and scrollbars are what made it difficult.
Below was the answer I needed:

      :




self.scroll = wx.ScrolledWindow(self, -1)
self.scroll.SetScrollbars(1, 1, 1000, 32400)
self.text_ctrl = wx.TextCtrl(self.scroll, wx.ID_ANY, style=...)
hsizer=wx.BoxSizer(HORIZONTAL)
hsizer.Add(self.text_ctrl, 1, wx.EXPAND)
mainsizer=wxBoxSizer(VERTICAL)
mainsizer.Add(self.scroll, 1, wx.EXPAND)
self.Setsizer(mainsizer)
self.Fit()
self.Show()

  :
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.