multiple panel in wxpython

こ雲淡風輕ζ 提交于 2020-01-06 05:37:10

问题


Is it possible to have multiple panel in wxpython? I want to have something like this:

import wx.grid
import sys

class Mat_Frame(wx.Frame):
    def __init__(self,parent):

        wx.Frame.__init__(self,wx.GetApp().TopWindow,title='Material Properties')
        self.panel=wx.Panel(self,-1)
        self.AdderPanel=wx.Panel(self.panel,-1)
        self.InputPanel=wx.Panel(self.panel,-1)
        self.OutputPanel=wx.Panel(self.panel,-1)
        HorSizer=wx.BoxSizer(wx.HORIZONTAL)
        HorSizer.Add(self.panel,proportion=1,flag=wx.EXPAND|wx.ALL)
        HorSizer.Add(self.AdderPanel,proportion=1,flag=wx.EXPAND|wx.ALL)
        HorSizer.Add(self.InputPanel,proportion=1,flag=wx.EXPAND|wx.ALL)
        HorSizer.Add(self.OutputPanel,proportion=1,flag=wx.EXPAND|wx.ALL)

I tried this but it is not working. I mean, I get weird window unsized properly. Am I doing something wrong here? Can somebody point me how to use multiple panels in wxpython?


回答1:


You can create as many Panels as you want. You've only created one though, then a series of tuples. You may want this:

self.panel=wx.Panel(self,-1,size=(x,x))
panel1=wx.Panel(self.panel,-1,size=(x,x))
panel2=wx.Panel(self.panel,-1,size=(x,x))

That will actually create several Panels, with the second two being children of the first one. Their layout isn't going to be friendly yet though - you're going to need to look into Sizers.




回答2:


Sorry, I just realized I had forgotten to set the sizer. It worked fine after that.



来源:https://stackoverflow.com/questions/9706505/multiple-panel-in-wxpython

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!