鼠标回调{点击功能}在 Qtile 关闭小部件 (archCraft linux) 中不起作用

问题描述 投票:0回答:1

我正在尝试使用简单的小部件在 Qtile 中创建一个简约的 GUI,用于关闭、重新启动和注销选项,但我在使用单击功能时遇到了问题 我用的是archcraft linux... 虽然我知道如何使用终端来做到这一点,但我正在尝试使我的 qtile WM 尽可能接近 桌面环境,主要是因为我是 Linux 新手

我已将以下代码片段添加到我的 config.py 中:

#these lines at beginning 
# Define colors
power_bar_bg = "#2E3440"
button_bg = "#3B4252"
button_fg = "#D8DEE9"

# Define functions for power actions
def shutdown(qtile):
    os.system("poweroff")

def restart(qtile):
    os.system("reboot")

def logout(qtile):
    qtile.cmd_shutdown()


#this is snippet that's near the end of the config file
screens = [
    Screen(
        right=bar.Gap(var_gap_right),
        left=bar.Gap(var_gap_left),
        top=bar.Gap(var_gap_top),
        bottom=bar.Bar(
            [
                widget.TextBox(
                    text="⏻",
                    foreground=button_fg,
                    background=button_bg,
                    fontsize=20,
                    padding=10,
                    mouse_callbacks={'Button1': shutdown}
                ),
                widget.TextBox(
                    text="↺",
                    foreground=button_fg,
                    background=button_bg,
                    fontsize=20,
                    padding=10,
                    mouse_callbacks={'Button1': restart}
                ),
                widget.TextBox(
                    text="➡️",
                    foreground=button_fg,
                    background=button_bg,
                    fontsize=20,
                    padding=10,
                    mouse_callbacks={'Button1': logout}
                ),
            ],
            30,  # height of the bar
            background=power_bar_bg,
        ),
    )
]

最终的桌面底部有这个

虽然这几乎是我所期望的,但问题是我无法单击按钮 并且鼠标回调没有按预期工作..它们根本没有工作

python user-interface configuration archlinux window-managers
1个回答
0
投票

在 Qtile 中,当您为小部件定义

mouse_callbacks
字典时,将在不带任何参数的情况下调用回调函数。但是,您可以通过回调函数内小部件的
qtile
属性访问 Qtile 管理器实例 (
qtile
)。

import os
from libqtile import qtile, widget, bar, layout, hook
# ... other necessary imports

power_bar_bg = "#2E3440"
button_bg = "#3B4252"
button_fg = "#D8DEE9"

def shutdown(widget):
    widget.qtile.cmd_spawn("systemctl poweroff")

def restart(widget):
    widget.qtile.cmd_spawn("systemctl reboot")

def logout(widget):
    widget.qtile.cmd_shutdown()

# ... (Your other configurations)

screens = [
    Screen(
        right=bar.Gap(var_gap_right),
        left=bar.Gap(var_gap_left),
        top=bar.Gap(var_gap_top),
        bottom=bar.Bar(
            [
                widget.TextBox(
                    text="⏻",
                    foreground=button_fg,
                    background=button_bg,
                    fontsize=20,
                    padding=10,
                    mouse_callbacks={'Button1': shutdown}
                ),
                widget.TextBox(
                    text="↺",
                    foreground=button_fg,
                    background=button_bg,
                    fontsize=20,
                    padding=10,
                    mouse_callbacks={'Button1': restart}
                ),
                widget.TextBox(
                    text="➡️",
                    foreground=button_fg,
                    background=button_bg,
                    fontsize=20,
                    padding=10,
                    mouse_callbacks={'Button1': logout}
                ),
            ],
            30,
            background=power_bar_bg,
        ),
    )
]
© www.soinside.com 2019 - 2024. All rights reserved.