Weird result from pyqt example: an image viewer - python

I'm a beginner of PyQt, and I'm reading some examples in tutorials.
When I build an image viewer from example, I find the result is weird.
https://github.com/Werkov/PyQt4/blob/master/examples/widgets/imageviewer.py
Why there is a blank area on the top left of main window? How can I remove it?

The white rectangle is the self.imageLabel object. It is white because of the self.imageLabel.setBackgroundRole(QtGui.QPalette.Base) in the main window constructor. Just comment it out and the rectangle will disappear.
The side effect of this will be that if you open a transparent image, its background will be dark gray (as the background of the rest of the window inside) and not white. If you want it white, move the line self.imageLabel.setBackgroundRole(QtGui.QPalette.Base) to the end of the open method and indent it four spaces.

Related

how to render html code to transparent background image with python

I have locally an .html file and I need to render it to no background image.
what I do now:
import imgkit
imgkit.from_file('test.html', 'out.png')
replace_white_pixels_to_transparent("out.png") # my function that's doing what it name says :)
output before cleaning the white pixels looks like:
And after replacing the white pixels with transperent:
So I do get a no background image, and when upscaling the qulity and zoom in the webkit options the result is much better.
the problem is that even if the image quality is crazy high the white pixels cleaning process will leave some close to white pixels on the edges of the elements and it will delete necessary white pixels (eg. the inner of the shapes supposed to be white, or white backgroung image etc).
My question basically is how to render the html straight to no background image?
instead of rendering the elements on white background and then remove it.
this works pretty nicely:
import imgkit
kitoptions = {
"transparent": "",
}
imgkit.from_file('test.html', 'out.png', options=kitoptions)

Resolution of the image in the top left of a window in Tkinter?

What's the appropriate resolution of the image in the top left corner of the Tkinter output window? Because as you can see in the photo, the picture of the clock is sharp and detailed, but when I put it in the corner (with the red arrow), the image loses a lot of quality; I can barely understand it's a clock. So, what's the right resolution? The original resolution of the clock is 256x256. Eventually, is there a way to remove the default feather icon and simply put no image in that space?

(Tkinter) Making a frame transparent without making the whole window transparent

I have a label that is the background image and a frame on that label that shows other images and buttons, but I have some white spaces. Is it possible to make those spaces transparent to show the background image?
I've tried making the background a color and making that color transparent with:
window.attributes("-transparentcolor", "#20fc03");
frame.configure(background="20fc03");
but it makes the whole window transparent showing my desktop.
I can provide code if needed, I just do not know what would be useful.

wxPython Frame Background transparent

Another question to wxpython.
I have a Frame with (at the moment) 3 Panels. All of them contain *.png pictures with transparent parts.
But behind these transparent parts there is the grey from the Frame background.
What I want is just a transparent background, that I can see for example my Desktop or whatever is behind the programm in that moment.
All I found was SetTransparent(0) but this made the full programm transparent and the other thing was to change the shape, but that dosen't made anything, except change width/heigth, if the shape has not the same properties.

How can I make the background of an image appear transparent without PIL?

I'm trying to make a GUI in tkinter that uses one image as an overlay on top of another, but when I place the image over the lower one, the transparent area of the image appears as grey.
I've searched for solutions to this, but all the results that I've found have pointed towards using PIL.
Is it possible for me to use transparent, or partially transparent images in the python tkinter module without using PIL?
You could use some basic photoshop tools like the magic wand tool to remove the background, but keep in mind, some PNG format images have a faint background. This is either in the from of a watermark, or the image background was rendered with a lower opacity than the rest of the image. Your GUI may also have a layer placed above the images by default. Does it appear on each image seperatly when loaded into the GUI?

Categories