Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Screenshot problem
#1
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'.
Reply
#2
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 »
Reply
#3
(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'.
Reply
#4
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()
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
(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'.
Reply
#6
(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'.
Reply
#7
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#8
(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. Smile
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'.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020