Portál AbcLinuxu, 14. května 2024 02:31
# relevantní část kódu gtk3
button = Gtk.Button()
button.set_image(image)
button.set_relief(Gtk.ReliefStyle.NONE)
grid.attach(button, 0, 0, 1, 1)
Řešení dotazu:
#!/usr/bin/python3 import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk win = Gtk.Window() # The Button grid = Gtk.Grid() win.add(grid) button_top = Gtk.Label("") button1 = Gtk.Button(); image = Gtk.Image.new_from_file("/tmp/image.png"); button1.set_name('img-left') button1.add(image) button2 = Gtk.Button() button2.set_name('img-right') image = Gtk.Image.new() image.set_from_file("/tmp/image.png") button2.add(image) grid.attach(button_top, 0, 0, 1, 1) grid.attach(button1, 0, 1, 1, 1) grid.attach(button2, 1, 1, 1, 1) win.connect("delete-event", Gtk.main_quit) style_provider = Gtk.CssProvider() css = """ #img-left { border: solid black 1px; margin: 5px; margin-right: 10px; padding: 0px; } #img-right { border: solid black 1px; margin: 5px; margin-left: 10px; margin-right: 5px; padding: 0px; } """ style_provider.load_from_data(css) Gtk.StyleContext.add_provider_for_screen( Gdk.Screen.get_default(), style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION ) win.show_all() Gtk.main()
Tiskni Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.