Canvas background color not saved - python-3.x

Tkinter canvas.postscript is not saving the canvas background.
Sizes of the canvas that are used throughout the Python code:
w = 800
h = 600
Function to be assigned to "SAVE CANVAS' button:
def save_canvas():
canvas.update()
canvas.postscript(file= r'Z:\\...\FILE.ps', height=h, width=w, colormode='color')
When I click on the button that has the save_canvas command assign, the file that is saved has no background as assigned in the widget. I changed the color to orange, green, etc. draw on it. Everything looks ok, but saving is without background. Same with .jpeg/.png
What do I need to call for saving the background? I'll be needing this as the application I build require images as background as well.

I don't believe the postscript command is designed to preserve the background color of the canvas widget. It only saves the items that appear on the canvas.
A simple solution is to draw a rectangle that is the exact size of the canvas, and change the color of that rectangle.

Related

Formatting Text to the Tkinter Progressbar

I got to know about adding the text to the progress bar as per this question:
Displaying percentage in ttk progressbar
It helps me but I need a few more adjustments to do to the answer.
I need the text (the percentage) to appear on the left side of the progressbar.
For this, I added 'side':'left' to the layout format for Horizontal.TProgressbar.label.
As under:
style.layout('text.Horizontal.TProgressbar',
[('Horizontal.Progressbar.trough',
{'children': [('Horizontal.Progressbar.pbar',
{'side': 'left', 'sticky': 'ns'})],
'sticky': 'nswe'}),
('Horizontal.Progressbar.label', {'side':'left','sticky': ''})])
However, this moves the text to extreme left. It overlaps the progressbar border and is not clearly readable.
I need to adjust the font and font color of this text. How do we change that?
To change the space between the label and the border you can add a padding element to the layout
style.layout('text.Horizontal.TProgressbar',
[('Horizontal.Progressbar.trough',
{'children': [('Horizontal.Progressbar.pbar',
{'side': 'left', 'sticky': 'ns'})],
'sticky': 'nswe'}),
('Horizontal.Progressbar.padding', {'side':'left'}),
('Horizontal.Progressbar.label', {'side':'left','sticky': ''})])
Then configure the padding with
style.configure('text.Horizontal.TProgressbar', padding=4)
You can change the font and color of the text using style.configure with the font and foreground options:
style.configure('text.Horizontal.TProgressbar', foreground="red", font='Arial 20')
There is a full example of creating such a progressbar in my answer to Progressbar with Percentage Label?.

How can clipping be prevented on a Qt QLabel?

I have a dialog created in Qt Designer with contents that resize when the window is resized.
When the window height is made too small, the text in the window clips as follows:
How do I prevent the labels from being clipped?
Most specifically, the window must not resize any smaller than the size of the word wrapped text without clipping.

Tkinter fullscreen leaves border

I am trying to make an image slide show application using Tkinter and Pillow. I would like the image to go full screen, so currently my code looks like this (I think these are all the important bits, ask me if you need to see more):
canvas = Canvas(root, width=screenwidth, height=screenheight, bg=‘black’)#screenwidth and height previously assigned (checked to be correct) variables containing screen dimensions.
image = image.resize((resizew, resizeh) Image.ANTIALIAS)
imagesprite = canvas.create_image(midx, midy, image=photo) #had changed our resized image to a tkinter photo image previously, midx and midy are just half the screen dimensions.
The problem:
No matter what settings I change there is always some form of grey bar around the edge of the window. I have tried changing the window size, changing the canvas size, setting the window geometry manually using root.geometry to no avail. However, some of the combinations of settings lead to there being fewer bars; I have seen between 1 and 3. Pictures of the output in its current state are attached. There are no errors in the shell, not (currently) is there a border on the left of the image
[1]: https://i.stack.imgur.com/1DLfg.jpg
You need to set highlightthickness=0 when creating the canvas:
canvas = Canvas(root, width=screenwidth, height=screenheight, bg='black', highlightthickness=0)

Make canvas background transparent - python

So I am making a Frogger game, but have run into a problem. For the collision detection, I am using the following to check if one Tkinter canvas object is overlapping another:
canvas.find_overlapping(*canvas.bbox(imageObj))
However, I made the background a canvas object as well:
background = self.canvas.create_image(0, 0, image = self.imageData["Background"], anchor = "nw")
So the program is detecting a collision between the player and an object 24/7. Is there any way around this? I searched SO and tried putting the background in a label, but when I packed the canvas over it the background disappeared (probably because the canvas was covering it).
I can't find a way to make the canvas transparent without making the objects on it transparent as well. I also do not want to calculate the x and y boxes of each object, as that is just cumbersome and unreliable.
If someone could suggest another way, that would be awesome.
The find_overlapping method returns a list of items. Just cycle through the list and ignore the background item.

Is there a way to put a background inside SVG

I need to make an SVG that is to be used as a background-image with "cover", so the tile in the mosaic could be rescaled.
I'd like to have the icon at a fixed size and the posibility to always fill with a background color, because, to make matters more complicated, my image is going to be inside a container that is inside the tile
this is my example
my icon should go inside that red outlined box, fixed size and the background in gray
could i get that done?

Resources