Posts: 741
Threads: 122
Joined: Dec 2017
Hi,
When a user wants to save a document , that is shown in the tKinter canvas area of the gui,
he hits a button, and a screenshot is taken to the clipboard , and saved. (Using the box(...) method to copy only the canvas part.)
I'm using pyscreenshot. Works like a charm.
But, when the user does this a second time in a row, the app goes haywire. (eg. it starts a second instance of the app)
I'm testing what could cause this behaviour, and my question is:
Can I "flush" the clipboard of a PC, to empty it from the screenshot that was taken an saved a moment before.
I have not found anything, but maybe "flush" is the wrong term.
And maybe i have to look outside pyscreenshot.
ANy ideas ?
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Posts: 4,798
Threads: 77
Joined: Jan 2018
Mar-05-2024, 08:11 AM
(This post was last modified: Mar-05-2024, 08:11 AM by Gribouillis.)
Why not use the canvas postscript method to save the canvas as postscript then convert the postscript image to another format?
Output: help(Canvas.postscript)
Print the contents of the canvas to a postscript
file. Valid options: colormap, colormode, file, fontmap,
height, pageanchor, pageheight, pagewidth, pagex, pagey,
rotate, width, x, y.
Also the pyscreenshot module says
Quote:The pyscreenshot module is obsolete in most cases. It was created because PIL ImageGrab module worked on Windows only, but now Linux and macOS are also supported.
An old trick to convert eps to postscript:
cv.postscript(file="circles.eps")
from PIL import Image
img = Image.open("circles.eps")
img.save("circles.png", "png") See also pillow image formats
« We can solve any problem by introducing an extra level of indirection »
Posts: 741
Threads: 122
Joined: Dec 2017
Mar-06-2024, 10:37 AM
(This post was last modified: Mar-06-2024, 10:37 AM by DPaul.)
(Mar-05-2024, 08:11 AM)Gribouillis Wrote: Why not use the canvas postscript method Yes, that is what I did before I turned to screenshots. It also works, but,
I found that this method caused a significant loss of quality in the image.
And since e.g. payer cards have already very small print, screenshots look much better when saved.
Paul
Edit: it would seem that ctypes is a possibility.
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Posts: 2,128
Threads: 11
Joined: May 2017
Have you tried ImageGrab ? It should work now on all Operating Systems. Before only Windows was supported for ImageGrab. It returns a Image object you can work with.
from PIL.ImageGrab import grab
def screenshot():
grab().show()
screenshot()
Posts: 741
Threads: 122
Joined: Dec 2017
(Mar-06-2024, 01:32 PM)DeaD_EyE Wrote: Have you tried ImageGrab? It should work No, I did not (with PIL).
I will try asap.
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Posts: 741
Threads: 122
Joined: Dec 2017
Mar-11-2024, 04:19 PM
(This post was last modified: Mar-11-2024, 04:20 PM by DPaul.)
(Mar-06-2024, 01:32 PM)DeaD_EyE Wrote: Have you tried ImageGrab? It should work now on all Operating System Tried it today, yes it works.
My current method allows a box to be defined, so I grab only a part of the scren.
bbox = (canvasAreaStart, 10, screenWidth, verPixels)
# Capture a specific region
canvasArea = ImageGrab.grab(bbox=bbox) Maybe that is possible via PIL too ?
Still am testing why I causes the app to start another instance.
thx,
paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Posts: 2,128
Threads: 11
Joined: May 2017
There is a bbox argument.
img = PIL.ImageGrab.grab(bbox=(0, 0, 90, 60)) I use X11. It grabs all physical screens, even if all_screens=False .
Maybe the option works on Wayland. If you have only one screen, then you don't care.
Posts: 741
Threads: 122
Joined: Dec 2017
Mar-12-2024, 06:59 AM
(This post was last modified: Mar-22-2024, 06:11 PM by DPaul.)
(Mar-11-2024, 08:32 PM)DeaD_EyE Wrote: have only one screen, then you don't care. Thanks, good show, ... and no I don't care.
Paul
Edit: I read that pyscreenshot should be considered obsolete.
PIL Imagegrab seems to do what it's supposed to.
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
|