Comments (4)
Why would you expect a (0, 0) there? get_mouse_pos
returns mouse coordinates relative to the viewport (local=False
) or to the active window (local=True
). Since you're binding the click handler to that red square, the "origin" I presume is the top left corner of that square, which is located at (window padding X, window paddingY) in window's local coordinates. The default padding is (8, 8) - exactly what you're seeing.
You can try to print that origin position like this:
print(f"Origin: {dpg.get_item_rect_min(sender)}")
from dearpygui.
@v-ein Thank you for your comment.
Why would you expect a (0, 0) there?
You can try to print that origin position like this:
I tried this. But, the following error occurs.
Mouse clicked at: [201.0, 175.0]
Traceback (most recent call last):
File "/home/user/dpg_example.py", line 8, in mouse_callback
print(f"Origin: {dpg.get_item_rect_min(sender)}")
File "/home/user/dpg-venv/lib/python3.10/site-packages/dearpygui/dearpygui.py", line 840, in get_item_rect_min
return internal_dpg.get_item_state(item)["rect_min"]
KeyError: 'rect_min'
from dearpygui.
My bad - it should have been dpg.get_item_rect_min(app_data[1])
since sender
is the click handler itself, and the clicked widget is passed via app_data
.
You'll also notice that get_item_rect_min
returns global coordinates. To get local ones, you can try get_item_pos
, but these will be relative to the window's outer rectangle, i.e. (0, 0) will be the top-left corner of the title bar, not of the window's client area. You can offset that by computing title bar height from font size and paddings, but it might be easier to use get_item_rect_min
and get_mouse_pos(local=False)
- from these, you can directly calculate mouse position within the image.
Yes, coordinate systems in DPG are a bit of a mess.
from dearpygui.
@v-ein Thank you for your help. I understood coordinate system.
from dearpygui.
Related Issues (20)
- get_value returns a string representation instead of the object itself HOT 2
- Showcase on Python.org HOT 5
- Error loading font for Chinese path HOT 1
- Can't use set_y_scroll for listbox HOT 1
- v1.11.0 doesn't seem to work on Apple Silicon (M1) HOT 6
- Option to bring absolutely positioned) button to front? HOT 3
- [HELP] Axis limit never update HOT 2
- get_item_rect_size for plot annotations? HOT 6
- Windows Access Violation while plotting non-empty X and empty Y arrays
- A guildline how to build DearPyGui with Windows 32-bit systems HOT 6
- Dear PyGUI can support the function of embedding a browser
- add_custom_series crashed when channel_count > 2 HOT 1
- Resizable table rows HOT 1
- Ability to customize styles for Ctrl-Tab panel and other built-in ImGui windows
- Local wheel guide outdated
- output_frame_buffer missing support in macosx aarch64
- Show/hide doesn't work on the legend in dpg.subplots
- dpg.hide() on plot_axis also hides the legend
- Tabs bar position not working. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dearpygui.