【问题标题】:wxpython toolbar textctrl spacingwxpython 工具栏 textctrl 间距
【发布时间】:2013-11-11 07:12:55
【问题描述】:

我在 wxPython 工具栏中有 textctrl,我不知道如何将它与图标 (22x22) 对齐,并且在工具栏图标和文本控件以及框架边框之间有一些间距/填充。

import wx

class MyGUI(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(500, 500))

        menubar = wx.MenuBar()
        file = wx.Menu()
        help = wx.Menu()
        file.Append(101, '&Open', 'Open a new document')
        file.Append(102, '&Save', 'Save the document')
        file.AppendSeparator()
        quit = wx.MenuItem(file, 105, '&Quit\tCtrl+Q', 'Quit the Application')
        quit.SetBitmap(wx.Image('media/22/actions/system-log-out.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap())
        file.AppendItem(quit)

        menubar.Append(file, '&File')
        menubar.Append(help, '&Help')
        self.SetMenuBar(menubar)
        self.CreateStatusBar()
        self.toolbar = self.CreateToolBar()

        textctrl = self.toolbar.AddControl( wx.TextCtrl( self.toolbar, wx.ID_ANY,size=(100, -1)))
        tconn = self.toolbar.AddLabelTool(wx.ID_UNDO, '', wx.Bitmap('media/22/actions/server-connect-icon.png'))
        tplay = self.toolbar.AddLabelTool(wx.ID_REDO, '', wx.Bitmap('media/22/actions/media-playback-start.png'))

        self.toolbar.AddSeparator()
        texit = self.toolbar.AddLabelTool(wx.ID_EXIT, '', wx.Bitmap('media/22/actions/stop.png'))
        self.toolbar.EnableTool(wx.ID_EXIT, False)
        self.toolbar.Realize()

class MyApp(wx.App):
    def OnInit(self):
        frame = MyGUI(None, -1, 'MyGUI')
        frame.SetBackgroundColour('#004681')
        frame.SetIcon(wx.Icon('media/launch.ico', wx.BITMAP_TYPE_ICO))
        frame.Show(True)
        return True


if __name__ == '__main__':
    app = MyApp(0)
    app.MainLoop()

【问题讨论】:

    标签: python python-2.7 user-interface wxpython


    【解决方案1】:

    工具栏小部件遵循操作系统本机工具栏的外观,因此无法更改。请参阅以下主题:

    其中有几个解决方法,使用空白图像或标签作为间距。或者,您可以使用水平框尺寸器创建自己的工具栏并将所有小部件添加到其中。然后你就可以使用 sizer 来把东西分开一点。

    【讨论】:

    • 完美,我创建了一个空白透明 png。但是尽管显示了工具栏,但它显示了框架的背景,不确定它是否是一个错误。还有什么方法可以动态替换工具栏图标,比如在点击时切换图标/位图本身。
    • 如果您正在滚动自己的工具栏,您可以只使用切换按钮小部件或位图小部件并在按钮的处理程序中更改位图。滚动您自己的工具栏的另一种方法是专门为工具栏创建第二个面板。然后,您可以独立于应用程序的其余部分设置其背景颜色。
    猜你喜欢
    • 2012-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-31
    • 1970-01-01
    相关资源
    最近更新 更多