I have issues about panels in wxpython

79 Views Asked by At

I want to do a interface with wxpython like this I have issues about embeding webview, button, textview and plots in different panels

and when I tried to embed a webview in panel3 it shown like little square on top right of the panel

please help me

import wx
import wx.html2 

class MyFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title)
        
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        
        panel1 = wx.Panel(self,-1 , pos=(1,1),size=(1600,50), style=wx.SUNKEN_BORDER)
        panel2 = wx.Panel(self,-1 , pos=(1,50),size=(1300,500), style=wx.SUNKEN_BORDER)
        panel3 = wx.Panel(self,-1 , pos=(1300,50),size=(300,500), style=wx.SUNKEN_BORDER)
        panel4 = wx.Panel(self,-1 , pos=(1,550),size=(1600,500), style=wx.SUNKEN_BORDER)
        

        panel1.SetBackgroundColour("BLUE")    #buttons in here
        panel2.SetBackgroundColour("RED")     #plots in here
        panel3.SetBackgroundColour("GREY")    #webview in here
        panel4.SetBackgroundColour("YELLOW")  #textview in here
        
        browser = wx.html2.WebView.New(panel3)
        browser.LoadURL("http://www.google.com")
        hbox.Add(browser,wx.EXPAND)
     
         

app = wx.App()
frame = MyFrame(None, -1, "Sizer Test")
frame.Show()
app.MainLoop()
1

There are 1 best solutions below

1
On

You have defined a Sizer but you haven't assigned it, with SetSizer.
I assume, in an attempt to force it to work, you have included postions for the panels. A Sizer removes the need to have positions, as the Sizer/Sizers perform that task for you.
If we remove the positions, assign some rational sizes and apply the Sizers, we get this.
It may not be what you are striving for but it's a starting point.

import wx
import wx.html2 

class MyFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title)
        
        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        panel1 = wx.Panel(self,-1 , size=(-1,100), style=wx.SUNKEN_BORDER)
        panel2 = wx.Panel(self,-1 , size=(-1,100), style=wx.SUNKEN_BORDER)
        panel3 = wx.Panel(self,-1 , size=(-1,400), style=wx.SUNKEN_BORDER)
        panel4 = wx.Panel(self,-1 , size=(-1,100), style=wx.SUNKEN_BORDER)
        

        panel1.SetBackgroundColour("BLUE")    #buttons in here
        panel2.SetBackgroundColour("RED")     #plots in here
        panel3.SetBackgroundColour("GREY")    #webview in here
        panel4.SetBackgroundColour("YELLOW")  #textview in here
        
        browser = wx.html2.WebView.New(panel3)
        browser.LoadURL("http://www.duckduckgo.com")

        hbox.Add(browser, proportion=1, flag=wx.EXPAND)
        panel3.SetSizer(hbox)

        vbox.Add(panel1, flag=wx.EXPAND)
        vbox.Add(panel2, flag=wx.EXPAND)
        vbox.Add(panel3, flag=wx.EXPAND)
        vbox.Add(panel4, flag=wx.EXPAND)
        self.SetSizer(vbox)     
         

app = wx.App()
frame = MyFrame(None, -1, "Sizer Test")
frame.Show()
app.MainLoop()

enter image description here