Open ingdariogiacomelli opened 3 months ago
IMO, it will be much complex and difficult to add elements to location (x, y) for the layout structure in PySimpleGUI.
What I can do now is to provide tkinter methods as workaround for your question, but no comment about it.
Example Code
import PySimpleGUI as sg
sg.theme("DarkBlue")
sg.set_options(font=("Courier New", 16))
layout = [
[sg.Text("\nWhat's your name?\n", expand_x=True, pad=(0, 0), key="Question")],
[sg.Input(key="Answer")],
[sg.Text()],
[sg.Push(), sg.Button('Ok'), sg.Button('Cancel')],
[sg.Text()],
]
window = sg.Window('Hello Example', layout, margins=(0, 0), finalize=True)
root = window.TKroot
x0, y0 = window.current_size_accurate()
base64_image = sg.EMOJI_BASE64_GUESS
image = sg.tk.PhotoImage(data=base64_image)
icon = sg.tk.Label(window.TKroot, text="Widget", image=image, compound=sg.tk.TOP, bg=sg.theme_background_color(), fg="white")
icon.place(x=x0, y=0, anchor=sg.tk.NE)
window.bind("<Button-1>", "Click")
no_action = list(map(lambda x:window[x].widget, ["Answer", "Ok", "Cancel"]))
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Cancel':
break
elif event == "Click":
e = window.user_bind_event
widget = e.widget
if widget in no_action:
continue
x = e.x_root - root.winfo_rootx()
y = e.y_root - root.winfo_rooty()
icon.place(x=x, y=y, anchor=sg.tk.CENTER)
window.close()
You can also refer https://github.com/jason990420/PySimpleGUI-Solution/issues/231
Yea, this one isn't something I'm interesting in adding to the PySimpleGUI SDK. It's a step too far outside the overall design direction. As Jason's shown, it's possible with tkinter calls. X,Y positioning and using other Element placement designs is a step away from the "Simple" part of PySimpleGUI just a tad.
Type of Issue (Enhancement, Error, Bug, Question)
Question
Environment
Operating System
Windows version ('10', '10.0.19041', 'SP0', 'Multiprocessor Free')
PySimpleGUI Port (tkinter, Qt, Wx, Web)
tkinter
Versions
Python version (
sg.sys.version
)3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 18:46:30) [MSC v.1929 32 bit (Intel)]
PySimpleGUI Version (
sg.__version__
)5.0.6
GUI Version (tkinter (
sg.tclversion_detailed
), PySide2, WxPython, Remi)8.6.10
Your Experience In Months or Years (optional)
Years Python programming experience Years Programming experience overall No Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)
Troubleshooting
These items may solve your problem. Please check those you've done by changing - [ ] to - [X]
Detailed Description
Hey, what about to have a way to put a sg.Frame() not encapsulated in the normal layout, but defined by its x, y location? maybe at runtime : I click a button and the frame appears magically ad x,y coordinates of the screen.
But obviously it should still remain valid the accessibility by window['-my-frame-'].... and values['-my-frame-'] ...
It's only a question. It is difficult to add this features? maybe sg.window( ... , layout , ... , xy_layout=my_other_layout , ... ) ? and clicking the button , I will set window['-my-frame-'].update(visible=True) ... and uala! :-D sometimes, having an alternative way of put a frame into the windows regardless ot actual composition of layout, should be useful...
Many thanks for attention!
Code To Duplicate
Screenshot, Sketch, or Drawing