简体   繁体   中英

wxpython set sizer background

i am using wxpython and trying to make an background to a sizer without any success, i searched in google without any results.

i try it with this boxsizer

wx.BoxSizer(wx.HORIZONTAL)

I just use panels for this sort of thing. You can set the color of the panel several different ways: you can use a named color, a wx.Color object, a predefined wx.Color object like wx.RED or a tuple of 3 integers.

Here's a simple example:

import wx

class MyPanel(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        self.SetBackgroundColour('white')

        main_sizer = wx.BoxSizer(wx.VERTICAL)
        for number in range(5):
            btn = wx.Button(self, label='Button {}'.format(number))
            main_sizer.Add(btn, 0, wx.ALL, 5)

        self.SetSizer(main_sizer)


class MyFrame(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, title='Background colors')
        panel = MyPanel(self)
        self.Show()

if __name__ == '__main__':
    app = wx.App(False)
    frame = MyFrame()
    app.MainLoop()

I wrote a little about this topic here:

You might also the wxPython wiki helpful:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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