wxPython GetBackgroundColour() function works differently on linux and windows platforms

前端 未结 1 1071
挽巷
挽巷 2021-01-26 01:33

I want to create an image in a wx Python application with the colour of the background.

[EDIT] On Windows this works perfectly:

[/EDIT]

but on

相关标签:
1条回答
  • 2021-01-26 02:12

    This is just to back up my original comments.
    I can only assume that your issue is something to do with your Theme or other setup you have on your box, although I of course reserve the right to be horribly wrong.
    This code, on Mint 19 (Ubuntu 18.04) Python 3.6 Wx 4.0.3 gtk2

    import wx
    
    class MainFrame(wx.Frame):
        def __init__(self):
            wx.Frame.__init__(self, None, -1, 'Image')
            sizer = wx.BoxSizer()
    
            sys_background = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BACKGROUND)
            print("default colour ", sys_background)
    
            static_bitmap_A = wx.StaticBitmap(self, wx.ID_ANY)
            bitmap = wx.Bitmap('/home/rolf/any2.png')
            static_bitmap_A.SetBitmap(bitmap)
            sizer.Add(static_bitmap_A, flag=wx.ALL, border=10)
    
            image = wx.Image('/home/rolf/any2.png')
            #colour = self.GetBackgroundColour()
            colour = sys_background
            red, green, blue = colour[0], colour[1], colour[2]
            print(red, green, blue)
            for row in range(image.GetSize()[0]):# -1 ):
                for column in range(image.GetSize()[1]):
                    image.SetRGB(row, column, red, green, blue)
            bitmap = wx.Bitmap(image)
            static_bitmap_B = wx.StaticBitmap(self, wx.ID_ANY,bitmap)
            sizer.Add(static_bitmap_B, flag=wx.ALL, border=10)
    
            self.SetSizerAndFit(sizer)
            self.Show()
    
    if __name__ == '__main__':
        screen_app = wx.App()
        main_frame = MainFrame()
        screen_app.MainLoop()
    

    Outputs (Theme Mint-X):

    default colour  (214, 214, 214, 255)
    214 214 214
    

    This continues to work properly, when changing the Theme, simply outputting different numbers for the colour values.

    Theme Mint-Y

    default colour  (240, 240, 240, 255)
    240 240 240
    

    It works whether using colour = self.GetBackgroundColour() or colour = sys_background

    0 讨论(0)
提交回复
热议问题