0

I want to draw a circle on the screen but it should be click-through and I should be able to click somethings behind in this circle. So far, I achieved to draw circle and made it transparent but i couldn't make it click-through. I know that it is possible with pywin32 win32con.WS_EX_LAYERED flag but there is no information about this on PySimpleGUI documentation. How can I solve this problem?

My current window configuration:

window = sg.Window('Sample window', layout,
                   keep_on_top=True,
                   auto_size_buttons=False,
                   grab_anywhere=False,
                   no_titlebar=True,
                   return_keyboard_events=False,
                   alpha_channel=0.8,
                   use_default_focus=False,
                   transparent_color='red',
                   finalize=True)

If it is not possible with PySimpleGUI, is it possible to do with pywin32 module combination?

Cengizz
  • 25
  • 2
  • 8
  • I assume you mean the tkinter version of PySimpleGUI. If so, I was able to draw using a Graph a red circle and then was able to click through the hole in the window and selected text in the next window under it. – Mike from PSG Feb 15 '20 at 22:53
  • @MikeyB Yeah I did that but the circle it self is not click-through right? :) – Cengizz Feb 17 '20 at 08:24
  • The transparent portion of the window was clickthrough. I don't know how else to phrase it. The hole in the window, however its created, I was able to interact with whatever I could see through the opening. If you run the PySimpleGUI test harness (PySimpleGUI.main()), there's a button that will make the window transparent to allow you to test stuff like this. You should be able to run it, click the button to make it transparent and then interact with anything visible through the window. – Mike from PSG Feb 17 '20 at 21:34

2 Answers2

2

The transparent_color property can be used to create "click-through" windows. All you need to do is make whatever you want to be click through the same color as the transparent_color. Here is an example where you can toggle the transparency of a shape in a canvas to the transparent color and make it click through.

import PySimpleGUI as sg
layout = [      
    [sg.Canvas(size=(100, 100), key= 'canvas',)],      
    [sg.T('Change circle color to:'), sg.Button('Red'), sg.Button('Blue')]      
    ]      

window = sg.Window('Sample window', layout,
               keep_on_top=True,
               auto_size_buttons=False,
               grab_anywhere=False,
               no_titlebar=True,
               return_keyboard_events=False,
               alpha_channel=0.8,
               use_default_focus=False,
               transparent_color='red',
               finalize=True)      
window.Finalize()      

canvas = window['canvas']     
cir = canvas.TKCanvas.create_oval(50, 50, 100, 100)      

while True:      
    event, values = window.read()      
    if event is None:      
        break      
    if event == 'Blue':      
        canvas.TKCanvas.itemconfig(cir, fill="Blue")      
    elif event == 'Red': 
        #Here is where the cirle changes to a recolor making it transparent and click through
        canvas.TKCanvas.itemconfig(cir, fill="Red")
Alessio
  • 3,404
  • 19
  • 35
  • 48
0
layout = [[sg.Button("Button) ],
    [sg.Graph(canvas_size =(400,100),
    graph_bottom_left=(-400,-400),
    graph_top_right=(400,400),
    background_color='red') ]]

window = sg.Window('Click through transparent',
  layout,background_color='red',keep_on_top=True,
  transparent_color='red', alpha_channel=.5,
  grab_anywhere=True, resizable=True).Finalize()

while True:
    event, values = window.Read()
    if event == sg.WIN_CLOSED:
        break 
    if event == 'Click':
        print(" Button Clicked")

Remember to put keep_on_top = True This works well on windows, don't know if other os