sudo apt-get install python3-gi
python
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='My Window')
self.set_size_request(300, 200)
button = Gtk.Button(label='Click me!')
button.connect('clicked', self.on_button_clicked)
self.add(button)
def on_button_clicked(self, button):
print('Button clicked!')
win = MyWindow()
win.show_all()
Gtk.main()
python
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='My Window')
self.set_size_request(300, 200)
label = Gtk.Label(label='Enter your name:')
label.set_halign(Gtk.Align.START)
entry = Gtk.Entry()
entry.set_width(200)
button = Gtk.Button(label='Submit')
button.connect('clicked', self.on_button_clicked)
self.add(label)
self.add(entry)
self.add(button)
def on_button_clicked(self, button):
name = entry.get_text()
print(f'You entered: {name}')
win = MyWindow()
win.show_all()
Gtk.main()
python
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='My Window')
self.set_size_request(300, 200)
button = Gtk.Button(label='Click me!')
button.connect('clicked', self.on_button_clicked)
self.add(button)
def on_button_clicked(self, button):
print('Button clicked!')
win = MyWindow()
win.show_all()
style =Gtk.CssProvider()
style.load_from_path('my-style.css')
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
style,
Gtk.STYLE_PROVIDER_PRIORITY_USER
)
Gtk.main()