如何删除 pygtk 中的 hover/clicked 效果?

How to remove hover/clicked effect in pygtk?

我想删除或关闭 pygtk 中按钮的悬停和单击效果。你有什么想法?我在这里找不到任何有用的东西 gtk.Button

我说的是这个:

Normal

Hover

Clicked

-你真的想要一个按钮吗?按钮和标签之间的主要区别在于这些效果(标签不会生成事件,但您可以通过将它们打包成 Gtk.EventBox)

-首先禁用引起影响的事件的方法如下:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
#  test_inert_button.py
#
#  Copyright 2017 John Coppens <john@jcoppens.com>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#
#


import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class MainWindow(Gtk.Window):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.connect("destroy", lambda x: Gtk.main_quit())
        self.set_size_request(400, 300)

        btn1 = Gtk.Button("One - inert button")
        btn2 = Gtk.Button("Two - active button")

        btn1.connect("enter-notify-event", self.on_leave)
        btn1.connect("button-press-event", self.on_leave)

        vbox = Gtk.VBox()
        vbox.pack_start(btn1, False, False, 0)
        vbox.pack_start(btn2, False, False, 0)

        self.add(vbox)
        self.show_all()

    def on_leave(self, btn, event):
        return True

    def run(self):
        Gtk.main()


def main(args):
    mainwdw = MainWindow()
    mainwdw.run()

    return 0

if __name__ == '__main__':
    import sys
    sys.exit(main(sys.argv))

on_leave 方法的 return True 告诉默认处理程序事件已处理,因此它不会产生效果。顶部按钮 One 没有反应,底部按钮仍然有反应。