PySimpleGUI / PySimpleGUI/PySimpleGUI

[Enhancement ] Keep graph coordinate system constant after graph element changes in size

Open
#6,451 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement Port - TK Question
Dominant language
Python
Stars
13.8k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

Question

Operating System

Windows 11

PySimpleGUI Port (tkinter, Qt, Wx, Web)

tkinter


Versions

Python version (sg.sys.version)

3.10.11

PySimpleGUI Version (sg.__version__)

4.60.4

GUI Version (tkinter (sg.tclversion_detailed), PySide2, WxPython, Remi)

8.6.12


Troubleshooting

These items may solve your problem. Please check those you've done by changing - [ ] to - [X]

  • Searched main docs for your problem www.PySimpleGUI.org
  • Looked for Demo Programs that are similar to your goal. It is recommend you use the Demo Browser! Demos.PySimpleGUI.org
  • None of your GUI code was generated by an AI algorithm like GPT
  • If not tkinter - looked for Demo Programs for specific port
  • For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • Run your program outside of your debugger (from a command line)
  • Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.org
  • Have upgraded to the latest release of PySimpleGUI on PyPI (lastest official version)
  • Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released
Detailed Description

I have a graph element with expand_x=True and expand_y=True and want to keep a constant coordinate system 0 <= x,y <= 200 even after the graph size changes. I set the TopRight attribute to (200, 200) every time the window size changes (configure event). Unfortunately the coordinate system does not respect the new TopRight value and instead scales proportionally with the graph element size.

Steps to reproduce:

  1. Run code below
  2. Confirm graph size is 200x200 in console output
  3. Move mouse cursor to top right corner: Cursor coordinates will say roughly 200x200
  4. Resize window to twice the width so that the console output says roughly 400x200
  5. Move mouse cursor to top right corner: Cursor coordinates will say roughly 400x200

Expected results:

After resizing and explicitly setting TopRight = (200, 200) I would expect the top right cursor coordinates to be 200x200. Instead the top right cursor coordinates are 400x200.

Code To Duplicate

import PySimpleGUI as sg


def main():
    layout = [
        [sg.Graph(canvas_size=(200, 200),
                  graph_bottom_left=(0, 0),
                  graph_top_right=(200, 200),
                  key="-GRAPH-",
                  motion_events=True,
                  enable_events=True,
                  background_color="white",
                  expand_x=True,
                  expand_y=True,
                  drag_submits=True)],
    ]

    window = sg.Window("Window", layout, finalize=True, resizable=True)
    window.bind("<Configure>", "-CONFIGURE-")

    while True:
        event, values = window.read()
        if event == sg.WIN_CLOSED:
            break

        graph = window["-GRAPH-"]

        if event == "-CONFIGURE-":
            print("New graph size:", graph.get_size())
            graph.TopRight = (200, 200)
        elif event == "-GRAPH-+MOVE":
            print("Mouse position:", values["-GRAPH-"])

    window.close()


if __name__ == "__main__":
    main()

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the supplied Python reproduction and inspect the Graph element's TopRight property together with the window event handling. Confirm how resizing changes the graph coordinate mapping, then verify that resetting TopRight to (200, 200) keeps cursor coordinates at that range after horizontal resizing.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
desktop
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.