This program maps a label with a hyperlink, non-focusable widgets (a spinner and a normal label) and optionally a button if an argument is given to the script.
import sys
import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk
class MainWindow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
box=Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
box11=Gtk.Box()
box12=Gtk.Box()
self.set_child(box)
box.append(box11)
box.append(box12)
#Subbox1
box11.append(Gtk.Label(label='ijk'))
l = Gtk.Label()
l.set_use_markup(True)
l.set_markup('<a href="https://wikipedia.com">Wikipedia link</a>;')
box11.append(l)
if len(sys.argv)>1:
box11.append(Gtk.Button.new())
#Subbox2
box12.append(Gtk.Spinner.new())
box12.append(Gtk.Label.new("end"))
class MyApp(Gtk.Application):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.connect('activate', self.on_activate)
def on_activate(self, app):
self.win = MainWindow(application=app)
self.win.present()
app = MyApp()
app.run()
If run with argument, the button is present, and then Tab will alternate a highlight border between the link and the button.
If run without argument, the button is absent, and then Tab alone will never cause a highlight, but Enter will cause the link to be loaded in the browser. More weirdly yet, if you insert random alphabetic keystrokes in between the Tab keystrokes, the link will eventually be highlighted:
What is going on here?