wxPython的GetBackgroundColour()函数在linux和Windows平台上的工作方式不同

编程入门 行业动态 更新时间:2024-10-26 02:32:25
本文介绍了wxPython的GetBackgroundColour()函数在linux和Windows平台上的工作方式不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在wx Python应用程序中使用背景色创建图像.

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

在Windows上可以正常使用:

On Windows this works perfectly:

[/EDIT]

但是在Linux上,我的代码给出了较浅的颜色.我在做什么错了?

but on linux my code gives a paler colour. What am I doing wrong?

self.GetBackgroundColour()返回的颜色是(225,225,225);较浅的颜色.实际的背景颜色是(212,212,212)

The colour returned by self.GetBackgroundColour() is (225, 225, 225); the paler colour. The actual background colour is (212, 212, 212)

[\ EDIT]

以下是使用其他主题拍摄的图像:

Here is an image taken using a different theme:

因此,根据以下Rolf的回答,它看起来像是Mate的问题,而不是主题的问题

So based on Rolf's answer below it looks like an issue with Mate and not the theme

import wx class MainFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'Image') sizer = wx.BoxSizer() static_bitmap_A = wx.StaticBitmap(self, wx.ID_ANY) bitmap = wx.Bitmap('any.png') static_bitmap_A.SetBitmap(bitmap) sizer.Add(static_bitmap_A, flag=wx.ALL, border=10) image = wx.Image('any.png') colour = self.GetBackgroundColour() red, green, blue = colour[0], colour[1], colour[2] #red, green, blue = 0, 0, 0 for row in range(image.GetSize()[0]): 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) static_bitmap_B.SetBitmap(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()

任何图像都可以代替any.png

Any image can be used in place of any.png

推荐答案

这只是为了备份我的原始评论. 我只能假设您的问题与您的主题或盒子上的其他设置有关,尽管我当然保留非常错误的权利. 在Mint 19(Ubuntu 18.04)Python 3.6 Wx 4.0.3 gtk2上的这段代码

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()

输出(主题Mint-X):

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.

主题Mint-Y

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

无论使用colour = self.GetBackgroundColour()还是colour = sys_background

更多推荐

wxPython的GetBackgroundColour()函数在linux和Windows平台上的工作方式不同

本文发布于:2023-11-16 10:05:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603307.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   方式   工作   平台上   wxPython

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!