Getting windows (client coordinates) for python window - python

I have loaded an image using Tkinter in Python. It opens up in a python window. If I try to get coordinates of a part of the image, it gives me coordinates relative to the python window that opened up. However, I would like to actually be able to find the client coordinates of that part of the image i.e. coordinates in relation to the actual computer screen.
I looked into using win32gui and somehow trying to get coordinates from the device context, however I could not figure out a way.
Any help is much appreciated!

You can use root.winfo_rootx() and root.winfo_rooty() to get the coordinates of the top left corner of the tkinter window. You can add those to the event.x and event.yto get the screen coordinates.

Related

How to draw shapes directly on screen(framebuffer?) with python on windows

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?

OpenCV imshow fix region of interest

I'm building a mini application on top of imshow. The application includes dragging the mouse when you hold down the left mouse button. Unfortunately when zoomed into the image dragging when holding the mouse down already exists within imshow. It moves the ROI of in the zoomed-in image. I have attached an image to make this more clear.
I would like to block this native imshow functionality as it seems to only exist on Ubuntu anyways. But I couldn't find any Flag or reference how to do it.

Overlay all screens and draw rectangle with a mouse

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.

pyautogui not moving window to correct location

I am using pyautogui to move a window to the top left corner of the screen. For some applications such as Excel and Skype, this works correctly. For other applications such as Chrome and Notepad, the window is instead moved to 10 pixels to the right of the upper left hand corner. Why is this happening?
Note that I am using python 3.6 and Windows 10.
See code example below.
import pyautogui
window = pyautogui.getWindow('MyChromeWindow')
window.move(0,0)
#window instead moves to (10, 0).
I can't recreate the problem , but you can overcome this issue wiht move to picture as i suppose (0,0) is standardbackroud rgb.

Using python for graphics projection?

If this is not the best place to ask this, please advise me on an alternative exchange.
I'm trying to create a matrix (N x N) and project it onto a wall using a projector. Each cell of the matrix will have the option to be color-coded or lit. So, given a matrix and a cell, the program will be able to colorize it.
Right now I can achieve this using the graphics.py library and Tkinter. However, when I connect my projector to my laptop via VGA, I have to drag the Tkinter window over and position it on the extended projector screen. It's a manual drag and re-positioning and this should be all automatic.
Are there any other methods (preferably in Python) of achieving this or something similar?
Thanks!
Set your laptop to mirror its screen instead of using the projector as an extended desktop. Then you won't have to drag Tkinter over. This is an OS / videocard setting and has nothing to do with Python.

Categories