I have an image that has a white background, how can I make this background invisible?
Its in a wx.StaticBitmap
wx.StaticBitmap(self, bitmap=wx.Bitmap('images/myimage.png'),pos=(0,0))
By invisible, I assume you mean transparent so that whatever is behind the image shines through.
This is not a function of widgets, but whatever you use to edit your image. You don't say!
I use microsoft visual studio. Here's a screenshot. Notice how the background, shown in a sort of blue-green in the editor - this will show up as transparent, which you can see happening in the column showing the fianl appearances.
Related
I have two questions:
Is it possible to increase somehow size of the icon in tkinter? Because the icon choosen by me is not clear visible when I use root.iconbitmap(..).
I also have another icon, but it's black and is not visible on black taskbar. What can I do?
I don't believe it's possible to change the size of the icon, unfortunately. However, make sure that the icon your using is a .ico file not some other format. .ico files show up bigger and clearer than other formats.
As for the black icon problem, the color of the taskbar is determined by your Windows color settings. There isn't much you can do other than to make an icon that works for both dark and light colors. Although you could get rid of the default taskbar and make your own taskbar in tkinter with whatever colors you would like, if that's something you would like to undertake.
I imagine this is a simple question and was hoping it someone would be able to help me figure it out. I have multiple wxpython sliders in my GUI but some of them have black boxes around.
The sliders are placed inside a StaticBox which is placed inside ScrolledPanel. It seems that those that are on top (i.e. are shown without the need to scroll the panel) look normal, as for the 'Annotation font size' but the ones that were hidden have black background behind it. Anyone has any ideas?
I thought it was because I was not calling Layout() but it doesn't make any difference.
I managed to fix this problem on my side. Maybe it helps you too. In my case, I have a lot of text boxes and sliders on a scrolled panel (wx.lib.scrolledpanel.ScrolledPanel):
Black boxes around sliders:
I am fixing it by setting the background color of the panel after I have finished populating it with graphic elements:
self.SetBackgroundColour('WHITE')
Here is the result:
No more black boxes around sliders:
In wxpython, you can change the transparency of a frame using 'SetTransparent()' function.
There is a sample app that shows the use of transparent frames here. However, the text also fades as the transparency changes (predictably). Is it possible to make it so the text always remains opaque while the background changes transparency?
wxPython 2.8.10, Python 2.6.2, Windows 7 x64
So I am having a bit of a wxPython issue I am hoping someone can say where I am going wrong. In my application I have Sliders where the background colour changes as you move the slider around. I do this via SetBackgroundColour from within a EVT_SLIDER handler. It mostly works, but I end up with a border of unchanged colour around the outer edge of the widget.
I have tried Refresh up the chain, RefreshRect on the top level Frame around the widget (and a few pixels further out), various combinations of Update and Layout, but nothing seems to erase it. The best I have managed is if I use something like:
frame = wx.GetTopLevelParent(slider)
rect = slider.GetRect()
slider.ClearBackground()
slider.SetBackgroundColour(wx.Colour(red,green,blue))
frame.RefreshRect(rect)
It will correctly draw the background box with the new colour without the border issue, but it will not repaint the slider itself.
However, if I click away so the focus is elsewhere, the border snaps to the new colour.
I could probably use an overlay or custom paint function but I am hoping there is something I am missing here that will get me the desired results.
Any suggestions?
(edited to add)
Looks like resizing the window manually corrects the issue, but Layout() does not.
It also functions correctly if you do the client size trick:
w,h = slider.GetClientSize()
slider.SetClientSize( (w+1,h) )
slider.SetClientSize( (w,h) )
I am adding some wx.StaticText objects on top of my main wx.Frame, which already has a background image applied. However, the StaticText always seems to draw with a solid (opaque) background color, hiding the image. I have tried creating a wx.Color object and changing the alpha value there, but that yields no results. Is there any way I can put text on the frame and have the background shine through? And furthermore, is it possible to make the text itself translucent? Thanks.
You probably need some graphics rendering widget. As far as I know, in wxPython you can use either built-in wxGraphicsContext or pyCairo directly. Cairo is more powerful. However, I don't know the details.
I would try aggdraw into a small canvas.
Any Static Text uses the platform's native label machinery, so you don't get that sort of control over it.