PySimpleGUI / PySimpleGUI

Python GUIs for Humans! PySimpleGUI is the top-rated Python application development environment. Launched in 2018 and actively developed, maintained, and supported in 2024. Transforms tkinter, Qt, WxPython, and Remi into a simple, intuitive, and fun experience for both hobbyists and expert users.
https://www.PySimpleGUI.com
Other
13.26k stars 1.84k forks source link

[Bug] 1px inner border on graph element #2726

Open Attocia opened 4 years ago

Attocia commented 4 years ago

Type of Issues (Bug)

Operating System

Windows 7

Python version

3.7.2

PySimpleGUI Port and Version

Version 4.17.0, port PySimpleGUI

Your Experience Levels In Months or Years

Approx. 1 year Python programming experience Approx. 2 years programming experience overall Have previously used another Python GUI Framework

You have completed these steps:

Description of Problem / Question / Details

When attempting to place an image on the edge or in the corner of a graph element, it seems there is a 1px inner border of the background colour which prevents the image from fully rendering.

Attached is the image used for the code provided and another one demonstrating the issue.

image

Expected result: The 20x20 image renders in the top left, with 1px of green on the edges. Actual result: The 20x20 image renders in the top left, however the 1px of green in contact with the edge of the graph is displayed as the blue background colour.

demonstration

Code To Duplicate

import PySimpleGUI as sg

graph_element = sg.Graph(canvas_size=(40, 40), graph_bottom_left=(0, 0), graph_top_right=(40, 40),
                         background_color="#000080", key="graph_element")

mainwin = sg.Window("Main window", [[graph_element]], background_color="#FF00FF",
                    no_titlebar=True, grab_anywhere=True).Finalize()

image = graph_element.DrawImage(filename="./image.png", location=(0, 40))
PySimpleGUI commented 4 years ago

I recall having some problems with the edges back when I made the Crossword Puzzle demo program. The workaround I used then was to add an "edge offset". It's not ideal, but will get you up and running while the root cause it being determined.

Thank you for a working bit of code. It's extremely helpful to have these.

jason990420 commented 4 years ago

Yes, If I shift all figures right and down one point, it will be fine. Just not sure if there's a bug in Graph methods. Here's the code show the problem. There are two invisible lines of rectangle, top one and left one, but right one and bottom one are OK. Checked by zoom software, it did miss all the points for x=0, and all the point for y=max.

The other problem If DrawRectangle with two points which has same x or same y, the line width will be 2, not 1. Also checked by zoom software.

import PySimpleGUI as sg
layout = [[sg.Graph(canvas_size=(100, 100),
                    graph_bottom_left=(0,0),
                    graph_top_right=(99, 99),
                    key='Graph')]]
window = sg.Window('Graph Test', layout=layout, finalize=True)
draw = window.find_element('Graph')

draw.DrawRectangle((0, 99), (99, 0))

while True:
    event, values = window.read()
    if event == None:
        break
window.close()