I want to remove or turn off this hover and clicked effect on button in pygtk. Do you have any ideas? I couldn't find anything useful here gtk.Button
I am talking about this:
-Do you really want a button? The main distinction between buttons and labels are those effects (labels don't generate events, but you can make them do so by packing them into a Gtk.EventBox)
-Here's how to disable the events that cause the effects in first place:
#!/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))
The on_leave method's return True
tells the default handler that events are handled so it won't do the effects. The top button One
doesn't react, the bottom one still does.