繁体   English   中英

wxPython:AuiManager的wx.Panel具有灰色的空白空间

[英]wxPython: wx.Panel of AuiManager has empty space of gray

我正在尝试用2个面板制作一个窗口。 一个面板只是一个笔记本面板。 第二个面板在顶部包含一个工具栏,在底部包含一个文本控件。 我想使用wx.aui.AuiManager在我的框架中排列此面板。

问题是我的自定义面板中很大的灰色空白空间

这是我的代码:

import wx
import wx.aui
import images # contains toolbar icons

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY,
                            "AUI Tutorial",
                            size=(600,400))

        self._mgr = wx.aui.AuiManager()
        self._mgr.SetManagedWindow(self)

        notebook = wx.aui.AuiNotebook(self)
        nb_panel = TabPanel(notebook)
        my_panel = MyPanel(self)
        notebook.AddPage(nb_panel, "First Tab", False)

        self._mgr.AddPane(notebook,
                          wx.aui.AuiPaneInfo().Name("notebook-content").
                          CenterPane().PaneBorder(False))
        self._mgr.AddPane(my_panel,
                          wx.aui.AuiPaneInfo().Name("txtctrl-content").
                          CenterPane().PaneBorder(False))
        self._mgr.GetPane("notebook-content").Show().Top().Layer(0).Row(0).Position(0)
        self._mgr.GetPane("txtctrl-content").Show().Bottom().Layer(1).Row(0).Position(0)

        self._mgr.Update()


class MyPanel(wx.Panel):
    """
    My panel with a toolbar and richtextctrl
    """
    def __init__(self,parent):
        wx.Panel.__init__(self,parent=parent,id=wx.ID_ANY)

        sizer = wx.BoxSizer(wx.VERTICAL)

        toolbar = wx.ToolBar(self,-1)
        toolbar.AddLabelTool(wx.ID_EXIT, '', images._rt_smiley.GetBitmap())
        self.Bind(wx.EVT_TOOL, self.OnExit, id=wx.ID_EXIT)

        toolbar.Realize()
        sizer.Add(toolbar,proportion=0,flag=wx.ALL | wx.ALIGN_TOP)

        text = ""
        txtctrl = wx.TextCtrl(self,-1, text, wx.Point(0, 0), wx.Size(150, 90),
                           wx.NO_BORDER | wx.TE_MULTILINE | wx.TE_READONLY|wx.HSCROLL)

        sizer.Add(txtctrl,proportion=0,flag=wx.EXPAND)        
        self.SetSizer(sizer)

    def OnExit(self,event):
        self.Close()


class TabPanel(wx.Panel):
    def __init__(self,parent):
        wx.Panel.__init__(self,parent=parent,id=wx.ID_ANY)

        sizer = wx.BoxSizer(wx.VERTICAL)
        txtOne = wx.TextCtrl(self, wx.ID_ANY, "")
        txtTwo = wx.TextCtrl(self, wx.ID_ANY, "")

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(txtOne, 0, wx.ALL, 5)
        sizer.Add(txtTwo, 0, wx.ALL, 5)
        self.SetSizer(sizer)


if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MyFrame()
    frame.Show()
    app.MainLoop()

那么,如何解决我的代码,使我不会出现占用MyPanel的灰色方块? 另外,我的工具栏按钮似乎没有运行self.OnExit()。 这是为什么?

谢谢您的帮助。

取出线:

self._mgr.GetPane("notebook-content").Show().Top().Layer(0).Row(0).Position(0)

至于OnExit()处理函数,它正在触发! 如果要退出该应用程序,请将其替换为app.Exit()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM