我想在屏幕上画一个圆,但它应该是点击式的,我应该能够点击这个圆圈后面的东西。到目前为止,我实现了画圆,并使其透明,但我不能让它点击。我知道使用pywin32 win32con.WS_EX_LAYERED
标志是可能的,但在PySimpleGUI文档中没有关于这方面的信息。我该如何解决这个问题?
我当前的窗口配置:
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)
如果不能使用PySimpleGUI,那么可以使用pywin32模块组合吗?
发布于 2020-06-03 19:12:32
transparent_color
属性可用于创建“点击直达”窗口。你所需要做的就是让你想要点击的任何东西和transparent_color
的颜色一样。下面是一个示例,在该示例中,您可以将画布中形状的透明度切换为透明颜色,并使其单击通过。
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")
发布于 2020-07-30 06:12:28
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")
记住写keep_on_top = True这在windows上运行得很好,不知道其他操作系统
https://stackoverflow.com/questions/60213167
复制相似问题