import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk class MyWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Welcome to Python GTK") self.set_default_size(400, 300) self.label = Gtk.Label(label="Hello, Python GTK!") self.add(self.label) win = MyWindow() win.connect("destroy", Gtk.main_quit) win.show_all() Gtk.main()
import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk class MyWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Welcome to Python GTK") self.set_default_size(400, 300) self.button1 = Gtk.Button(label="Click me!") self.button1.connect("clicked", self.on_button_clicked) self.add(self.button1) def on_button_clicked(self, widget): print("Button clicked!") win = MyWindow() win.connect("destroy", Gtk.main_quit) win.show_all() Gtk.main()
import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk class MyWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Welcome to Python GTK") self.set_border_width(10) button = Gtk.Button(label="Open dialog") button.connect("clicked", self.on_button_clicked) self.add(button) def on_button_clicked(self, widget): dialog = Gtk.MessageDialog(parent=self, flags=0, message_type=Gtk.MessageType.INFO, buttons=Gtk.ButtonsType.OK, text="This is an example of a GTK dialog box.") dialog.run() dialog.destroy() win = MyWindow() win.connect("destroy", Gtk.main_quit) win.show_all() Gtk.main()This code creates a GTK window with a button. When the button is clicked, it opens a dialog box with the message "This is an example of a GTK dialog box." The user can click "OK" to close the dialog box. In conclusion, the package library used in these examples is "gi.repository Gtk".