首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PySimpleGUI如何制作透明的点击窗口?

PySimpleGUI如何制作透明的点击窗口?
EN

Stack Overflow用户
提问于 2020-02-14 01:07:31
回答 2查看 1.7K关注 0票数 0

我想在屏幕上画一个圆,但它应该是点击式的,我应该能够点击这个圆圈后面的东西。到目前为止,我实现了画圆,并使其透明,但我不能让它点击。我知道使用pywin32 win32con.WS_EX_LAYERED标志是可能的,但在PySimpleGUI文档中没有关于这方面的信息。我该如何解决这个问题?

我当前的窗口配置:

代码语言:javascript
运行
复制
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模块组合吗?

EN

回答 2

Stack Overflow用户

发布于 2020-06-03 19:12:32

transparent_color属性可用于创建“点击直达”窗口。你所需要做的就是让你想要点击的任何东西和transparent_color的颜色一样。下面是一个示例,在该示例中,您可以将画布中形状的透明度切换为透明颜色,并使其单击通过。

代码语言:javascript
运行
复制
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")
票数 2
EN

Stack Overflow用户

发布于 2020-07-30 06:12:28

代码语言:javascript
运行
复制
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上运行得很好,不知道其他操作系统

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60213167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档