python - wxpython: small square panel in corner -


iam trying place small square panel(panel2) @ bottom rignt corner of panel(panel1).

the panel1 should fill entire frame , expand frame resized, squarepanel (panel2) should remain without expanding or resizing.

something this:

enter image description here

i think iam missing small thing can't figure out how acheive this. square panel expands along panel1 , don't want happen.

here's simplified code:

import wx  class myframe(wx.frame):     def __init__(self, parent, id, title):         wx.frame.__init__(self, parent, id, title,size=(250, 250))          #toppanel = wx.panel(self)          panel1 = wx.panel(self, -1)         panel2 = wx.panel(panel1, -1, size = (100,100))         panel2.setbackgroundcolour('gray')         s = wx.boxsizer(wx.vertical)         s.add(panel2,1, wx.align_right | wx.align_bottom)         panel1.setsizer(s)         sizer = wx.boxsizer(wx.vertical)         sizer.add(panel1,1,flag = wx.expand)         self.setsizer(sizer)  class myapp(wx.app):      def oninit(self):          frame = myframe(none, -1, 'frame')          frame.show(true)          return true  app = myapp(0) app.mainloop() 

this trivial. need use 2 boxsizers effect desire. see code below:

import wx  ######################################################################## class smallpanel(wx.panel):     """"""      #----------------------------------------------------------------------     def __init__(self, parent):         """constructor"""         wx.panel.__init__(self, parent, size=(50,50))         self.setbackgroundcolour("red")   ######################################################################## class mainpanel(wx.panel):     """"""      #----------------------------------------------------------------------     def __init__(self, parent):         """constructor"""         wx.panel.__init__(self, parent)          top_sizer = wx.boxsizer(wx.vertical)         h_sizer = wx.boxsizer(wx.horizontal)          top_sizer.addstretchspacer(prop=1)          mini_panel = smallpanel(self)          h_sizer.addstretchspacer(prop=1)         h_sizer.add(mini_panel, 0, wx.all, 5)         top_sizer.add(h_sizer, 0, wx.expand)         self.setsizer(top_sizer)   ######################################################################## class mainframe(wx.frame):     """"""      #----------------------------------------------------------------------     def __init__(self):         """constructor"""         wx.frame.__init__(self, none, title="panels")         panel = mainpanel(self)         self.show()  if __name__ == '__main__':     app = wx.app(false)     frame = mainframe()     app.mainloop() 

if run code, should see this:

enter image description here


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -