Comments (4)
There's no method to move the pointer cursor in PySimpleGUI, but it can be done by tkinter code after window finalized.
window.TKroot.event_generate('<Motion>', warp=True, x=x, y=y)
It is a little complex to convert between tkinter Canvas coords and user's coordinates.
Demo Code
import PySimpleGUI as sg
def draw_line(x0, y0, x1, y1):
x2, y2 = graph._convert_canvas_xy_to_xy(x1, y1)
window.TKroot.event_generate('<Motion>', warp=True, x=x2+dx, y=y2+dy)
graph.draw_line((x0, y0), (x1, y1), color='white', width=5)
size = xmax, ymax = (500, 500)
width, height = (400, 400)
layout = [
[sg.Graph(size, (0, xmax), (ymax, 0), pad=(0, 0), background_color='Green', key="Graph")],
[sg.Push(), sg.Button("Draw"), sg.Push()],
]
window = sg.Window("Cursor location", layout, margins=(0, 0), finalize=True)
graph = window['Graph']
draw, x0, y0 = False, None, None
dx, dy = graph.widget.winfo_x(), graph.widget.winfo_y()
while True:
event, values = window.read(timeout=50)
if event == sg.WIN_CLOSED:
break
elif event == "Draw":
draw, x0, y0, x1, y1 = True, 50, 250, 50, 250
graph.erase()
elif event == sg.TIMEOUT_EVENT and draw:
x1 += 10
draw_line(x0, y0, x1, y1)
if x1 >= 450:
draw, x0, y0 = False, None, None
else:
x0, y0 = x1, y1
window.close()
from pysimplegui.
I don't know if I've done something wrong, but when I click 'Draw' the pointer just stays put. The line is drawn, but the cursor doesn't move.
from pysimplegui.
It maybe "Platform dependent", so work on my WIN10, but not work on your Linux.
Here with the library pyautogui
import pyautogui
import PySimpleGUI as sg
layout0 = [
[sg.Button(f'({x:0>3d}, {y:0>3d})', key=(x, y), font=("Courier New", 10))
for x in range(100, 1000, 200)]
for y in range(50, 200, 50)
]
layout = [
[sg.Graph((1000, 200), (0, 200), (1000, 0), pad=(0, 0), background_color="green", key="Graph")],
[sg.Push(), sg.Column(layout0), sg.Push()],
]
window = sg.Window("Cursor location", layout, margins=(0, 0), finalize=True)
graph = window['Graph']
figure = None
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif isinstance(event, tuple):
x1, y1 = event
x2, y2 = graph._convert_canvas_xy_to_xy(x1, y1)
dx, dy = graph.widget.winfo_rootx(), graph.widget.winfo_rooty()
pyautogui.moveTo(x2+dx, y2+dy)
if figure:
graph.delete_figure(figure)
figure = graph.draw_text(f"({x1}, {y1})", (x1, y1), color='white')
window.close()
from pysimplegui.
Yeah, I think it is, still not working, thanks anyway 👍
from pysimplegui.
Related Issues (20)
- Flask click SystemError when used with pySimpleGUI output redirect HOT 1
- [Question] How to trap an event HOT 2
- [Enhancement] CI friendly handling for the first time installation dialog HOT 3
- [Question] How to update class parameter within inherited class HOT 4
- [Question] How To Re-Enter Data For A Specific Field - AND 'CR to act like TAB HOT 1
- [ Bug] sg.ColorChooserButton Unless Additional Tkinter Import HOT 1
- [Bug] Hitting the image-count limit [Fail to create pixmap with Tk_GetPixmap in TkImgPhotoInstanceSetSize] HOT 6
- [Question] Import error HOT 3
- [Question] Change focus highlight when tabbing to button HOT 8
- [ Enhancement/Bug/Question] NOTE - you can also call sg.main() or sg.main_open_github_issue() to post an issue HOT 1
- [ Question] Compiling Errors since License validation HOT 2
- [ Bug] Broken Doc Link HOT 2
- [Question] NOTE - Table get doesn't work HOT 6
- [ Enhancement] allow arrowheads for lines in tkinter graphs HOT 8
- [Question] Question of shortcut HOT 17
- [Question] How to Use PySimpleGui Programs on Other PCs HOT 1
- [ Question] How to detect when we manually enter a value in combo box in Pysimple GUI HOT 1
- [Bug] Table colored rows flashes when updating in 5.0, while they didn't in 4.x HOT 10
- [Question] No right_click_menu in Combo HOT 3
- [Enhancement] Reusing Context Menu HOT 6
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 pysimplegui.