MMah
MMah

Reputation: 13

wxpython scrolledwindow not displaying

Relatively new to python (2.7) and trying to figure out wxpython (so I apologise in advance for any poor use of code). I've got a GUI of which I have multiple switchable panels on a frame. I need the frame to be scrollable, so I've used ScrolledWindow but now some of the of the GUI elements which are below the initial frame size do not show upon scrolling on.

I've found that changing my monitor resolution solves the problem, but I want to be able to have this working regardless of resolution.

Below is an example of the problem I'm having (doesn't display hi4 and cuts off hi4)

import wx
from apanel import apanel

class simpleapp_wx(wx.Frame):
    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,id,title,size=(1000,1100))
        self.parent=parent
        self.scroll = wx.ScrolledWindow(self, -1)
        self.scroll.SetScrollbars(1,1,1000,1100)
        button0=wx.Button(self.scroll,-1,"hi0",(100,610))
        self.panel=apanel(self.scroll)
        self.CreateStatusBar()
        self.sizer= wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.panel, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.Show(True)

app=wx.App(False) 
frame=simpleapp_wx(None,-1,'Demo')
frame.Show()
app.MainLoop()      

and panel is in another class (in a seperate file I called apanel.py) import wx

class apanel(wx.Panel):
    def __init__(self,parent):
        wx.Panel.__init__(self,parent=parent)
        button=wx.Button(self,-1,"hi",(800,60))
        button2=wx.Button(self,-1,"hi2",(200,600))
        button3=wx.Button(self,-1,"hi3",(800,800))
        button4=wx.Button(self,-1,"hi4",(500,900))
        button5=wx.Button(self,-1,'hi5',(10,100))

Upvotes: 1

Views: 523

Answers (1)

user6320679
user6320679

Reputation:

I've found some errors in your code, it's simple to solve. Look the working panel bellow:

class simpleapp_wx(wx.Frame):
    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,id,title,size=(1000,1100))
        self.parent=parent

        self.scroll = wx.ScrolledWindow(self, -1)
        self.scroll.SetScrollbars(1,1,1000,1100)
        self.CreateStatusBar()

        sizer = wx.BoxSizer(wx.VERTICAL)
        self.scroll.SetSizer(sizer) # The scrolledWindow sizer
        self.panel = wx.Panel(self.scroll)
        sizer.Add(self.panel, 0, wx.EXPAND)
        button0=wx.Button(self.panel,-1,"hi0",(100,610))

Remarks:

  • If you use a scrolled window, create a sizer, and set the sizer in scrolled window.
  • The panel apanel need to be added on scrolled sizer created in line above.
  • The panel not resizing because simpleapp_wx (Frame) was set your size by the created BoxSizer, the order is inverse.
  • If you add some button after, put the apanel with parent, not scrolledwindow.

I suggest to you to use wxPython demo and docs: http://www.wxpython.org/download.php have a bunch of working examples.

Good luck in your wxpython studies!

Upvotes: 1

Related Questions