I am working on tiny program to capture screen print, I want to do it in a similar fashion that Win Snipping Tool is working. First I need to overlay all screens with a 50% opacity layer and then, using the mouse, draw a rectangle and read vertices coordinates. Honestly, I have no idea how to bite this. I tried with win32api / gui and it is great to get mouse coordinates, but still was unable to draw a rectangle. My idea (one of many) is to (using PIL / ImageGrab) take shots of both displays, put an overlay and print them as a full screen on all windows, but I failed while doing this. Other idea is to take img grab and create two new windows using BeeWare / Toga (that is GUI framework I am using) in full screen, but I was unable to find any method to open window on second display. Any ideas and hints will be greatly appreciated, I am really counting on you, as I feel I reached dead end.
Well,It is very easy to use tkinter.
Ok,It is the principle when I make my screenshot application:
User presses the button to start.
Make a new window whose width and height should full cover all the screens,and hide the title bar(If it is had to achieve,maybe use width=9999 and height=9999).
Take a screenshot of all the desktop(You can use ImageGrab.grab((),all_screens=True)) to do that.
Make the screenshot showed in a Canvas(I know that toga have this widget).
Start your mouse listener thread and save the position of pressed.
When user moves his mouse,create a rectangle(toga's Canvas have a function rect()).Maybe use this rect(pressed_x,pressed_y,move_x,move_y).And delete the last rectangle(Then it will always show only one rectangle).
When user released his mouse,save the position of released.And use ImageGrab.grab((pressed_x,pressed_y,released_x,released_y),all_screens=True) to crop the selected area.
If you want to show it in application interface.toga has a widget called ImageView.You can put the image in it.
Related
I'm trying to develop a code that open an image where you can select a point quit the mouse and drag to form a rectangle until you don't release the left button.
Then from python I should receive the starting coordinates and the height and width in pixel of the rectangle, how can I do it?
I saw that the packages argparse and cv2 can be used, but I don't really know how to approach it.
I won't do the job for you but I'm willing to help.
You will need 2 blocks of code:
an image displayer
a mouse-event listener
To start, you may forget about the image displayer. You may concentrate on the mouse listener while you draw your rectangle anywhere on the screen.
Select a mouse listener library. There are many on pypi.org.
I propose pynput because it is easy to work with and is well documented.
read documentation (focus on "on_click")
write your code to implement your mouse listener. It's simple (less than 10 lines). At the end of your program, add a statement:
input(">")
run your program. Click anywhere on the screen and drag to another point. Release.
your on_click() function will be called twice (once for button press and once for button release). Record the two sets of X-Y coordinates (unit is pixels).
once the button is released, compute the size of the rectangle (in pixels).
press any key on the keyboard to end the program.
Once your program is working you may work on the imager. If the image is large, you may have to use a scaling factor to reduce it. You will have to introduce the scaling factor in your sizing equations.
When a program skeleton will exist, do not hesitate to ask questions.
Asking for help when there is no visible sweat will not bring you many answers.
The title explains it self basically, I want to draw for example a rectangle on a specific coordinate on the screen, using Python, how to achieve this?
I hear PyGame mentioned frequently, but I need a solution that would allow me to click through the shape, and as far as I understand you definitely need a Pygame window to draw anything on the screen and that would prevent clicking on whatever it is underneath, am I correct?
I am trying to write a Python script that can play a simple Android game. In the game, a line of seemingly equally-spaced colored dots are moving from right to left. The dots movement happen in steps and not smoothly. The space between the dots is colored white. The goal is to quickly click the button corresponding to the color of the dot in the middle of the screen.
In my current implementation I use pyautogui to take a screenshot, analyze the the color of the dot in that location, and click the corresponding button. However, I only take screenshots at fixed intervals, but it seems to me that there is some source of randomness in the pacing of the dots preventing me from achieving a high score.
I am looking for a way to write the script such that the arrival of a colored dot to a fixed location on the screen is the trigger to clicking the button. The method should not be time-consuming otherwise I will lose the game.
I'm using pygame and I've been working so far in a large monitor, but now I need to work on a small laptop, whose screen is much smaller than the mentioned monitor. The dimensions I gave to the display surface and the items blitted to it work well on the previous monitor but it is too large on the laptop and therefore I cannot reach all buttons. Since I can't seem to find a way to resize everything proportionaly, is there an easy way to add a vertical and horizontal scroll bar in order to navigate around the display surface?
Thank you
I don't think that you can add a scroll bar. What you can do is shift the x or y of everything when you press the corresponding arrow keys. But as said by Ted Klein Bergman, it is better to simply resize everything.
I'm looking to make a Python program, that while running in the background (e.g. started through command line), will change the screen resolution of Windows (and shift the screen position). And then the user is free to continue to use their computer in this different resolution.
E.g.: (fake code below)
import os
os.changeResolution(800,600)
# the entire windows desktop resolution changes to a (800,600) box, with black/empty around it
os.changeScreenPosition(100,200)
# shifts the (800,600) window of the desktop to position (100,200)
while 1:
# do nothing, just keep the screen like we set it above while this little python program is running somewhere
continue
Picture below showing before/after:
after:
(screen is shrunk to new resolution, position is offset, background surrounding is black)
Now while this program is running minimized somewhere the user can go about their other desktop tasks. Is this possible with Python and Windows 10?
As a follow-up, what if I wanted to change the shape, from say a rectangular box, to a circle? E.g. to distort / bulge the screen.
Resizing the window will only make it fill your monitor at a lower resolution.
You can mess about with the magnify function to make it larger or live copy an area at the same resolution.
You can use thumbnails (the way windows 10 shows a preview when you hover over a window in the task bar) to make it look smaller, but it won't pass control to a smaller window.
Both are by the DWM (Desktop Window Manager) and don't let you intervene with the image short of adjusting the colour (magnify can tint the window or make it black and white)
Distorting to a round window is a whole can of worms. There are a few options explored in my old post below. I've still to give it a go, when I get some time, but think I'll be going down the route of trying to hook into DWM.
Realtime video processing for the complete Windows desktop