如何在pygtk中删除悬停/点击效果?

时间:2017-11-28 09:19:52

标签: python python-2.7 button pygtk

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

我在说这个:

Normal

Hover

Clicked

1 个答案:

答案 0 :(得分:0)

- 你真的想要一个按钮吗?按钮和标签之间的主要区别是那些效果(标签不会生成事件,但您可以通过将它们打包到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没有反应,底部按钮仍然有效。