Last active
November 9, 2019 15:08
-
-
Save juliendkim/eda9d89272b97998108c7de228b06a15 to your computer and use it in GitHub Desktop.
GObject(GTK3+) with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ brew install pkg-config gobject-introspection libffi gtk+3 | |
$ export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.2.1/lib/pkgconfig | |
$ export LC_ALL=en_US.UTF-8 # ko_KR.UTF-8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python3 -m venv venv | |
$ source venv/bin/activate | |
$ pip install --upgrade pip setuptools | |
$ pip install pycairo pygobject |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- Generated with glade 3.22.1 --> | |
<interface> | |
<requires lib="gtk+" version="3.20"/> | |
<object class="GtkWindow" id="main_window"> | |
<property name="can_focus">False</property> | |
<child> | |
<object class="GtkGrid"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<child> | |
<object class="GtkButton" id="button_hello"> | |
<property name="label" translatable="yes">button</property> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="receives_default">True</property> | |
<signal name="pressed" handler="on_button_hello_pressed" swapped="no"/> | |
</object> | |
<packing> | |
<property name="left_attach">0</property> | |
<property name="top_attach">0</property> | |
</packing> | |
</child> | |
<child> | |
<object class="GtkButton" id="buggon_quit"> | |
<property name="label" translatable="yes">Quit</property> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="receives_default">True</property> | |
<signal name="pressed" handler="on_button_quit_pressed" swapped="no"/> | |
</object> | |
<packing> | |
<property name="left_attach">1</property> | |
<property name="top_attach">0</property> | |
</packing> | |
</child> | |
</object> | |
</child> | |
</object> | |
</interface> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gi | |
gi.require_version('Gtk', '3.0') | |
from gi.repository import Gtk | |
class Handler: | |
def on_button_hello_pressed(self, button): | |
print('Hello') | |
def on_button_quit_pressed(self, button): | |
Gtk.main_quit() | |
if __name__ == '__main__': | |
builder = Gtk.Builder() | |
builder.add_from_file("main.glade") | |
builder.connect_signals(Handler()) | |
window = builder.get_object("main_window") | |
window.show_all() | |
Gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment