樹心幽徑

« 20180530解決acer電腦win10休眠後無法開機問題 | Main | 20180602在ubuntu裝gtk-3-examples並執行 gtk3-demo 、gtk3-icon-browser及gtk3-widget-factory »

20180602在ubuntu裝glade GUI 介面編輯程式並編譯執行gtk5.c程式
2018/06/02,14:29

treehrt@treehrt-fire:~/mysqlc$ sudo apt-get install glade

下列的額外套件將被安裝:
  libgladeui-2-6 libgladeui-common
下列【新】套件將會被安裝:
  glade libgladeui-2-6 libgladeui-common
升級 0 個,新安裝 3 個,移除 0 個,有 187 個未被升級。
需要下載 810 kB 的套件檔。
此操作完成之後,會多佔用 7,685 kB 的磁碟空間。
是否繼續進行 [Y/n]? [Y/n] y
下載:1 http://tw.archive.ubuntu.com/ubuntu xenial/universe amd64 libgladeui-common all 3.18.3-1 [97.4 kB]
下載:2 http://tw.archive.ubuntu.com/ubuntu xenial/universe amd64 libgladeui-2-6 amd64 3.18.3-1 [480 kB]
下載:3 http://tw.archive.ubuntu.com/ubuntu xenial/universe amd64 glade amd64 3.18.3-1 [233 kB]
取得 810 kB 用了 1秒 (577 kB/s)
選取了原先未選的套件 libgladeui-common。
(讀取資料庫 ... 目前共安裝了 424034 個檔案和目錄。)
準備解開 .../libgladeui-common_3.18.3-1_all.deb ...
解開 libgladeui-common (3.18.3-1) 中...
選取了原先未選的套件 libgladeui-2-6。
準備解開 .../libgladeui-2-6_3.18.3-1_amd64.deb ...
解開 libgladeui-2-6 (3.18.3-1) 中...
選取了原先未選的套件 glade。
準備解開 .../glade_3.18.3-1_amd64.deb ...
解開 glade (3.18.3-1) 中...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu5.1) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20160824-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for mime-support (3.59ubuntu1) ...
Processing triggers for hicolor-icon-theme (0.15-0ubuntu1) ...
設定 libgladeui-common (3.18.3-1) ...
設定 libgladeui-2-6 (3.18.3-1) ...
設定 glade (3.18.3-1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...

(2)用glade製作產生如下檔(window_main.glade)

treehrt@treehrt-fire:~/mysqlc$ cat window_main.glade
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
  <requires lib="gtk+" version="3.12"/>
  <object class="GtkWindow" id="window_main">
    <property name="can_focus">False</property>
    <property name="title" translatable="yes">樣版視窗</property>
    <property name="default_width">634</property>
    <property name="default_height">480</property>
    <signal name="destroy" handler="on_window_main_destroy" swapped="no"/>
    <child>
      <object class="GtkImage" id="image1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="pixbuf">Firefox_wallpaper.png</property>
      </object>
    </child>
  </object>
</interface>
treehrt@treehrt-fire:~/mysqlc$

 
treehrt@treehrt-fire:~/mysqlc$

(3)用vi編寫如下程式(gtk5.c)

treehrt@treehrt-fire:~/mysqlc$ cat gtk5.c
// REF: https://prognotes.net/2015/06/gtk-3-c-program-using-glade-3/
#include <gtk/gtk.h>

int
main (int    argc,
      char **argv)
{


    GtkBuilder      *builder;
    GtkWidget       *window;
 
    gtk_init(&argc, &argv);
 
    builder = gtk_builder_new();
    gtk_builder_add_from_file (builder, "window_main.glade", NULL);
 
    window = GTK_WIDGET(gtk_builder_get_object(builder, "window_main"));
    gtk_builder_connect_signals(builder, NULL);
 
    g_object_unref(builder);
 
    gtk_widget_show(window);               
    gtk_main();
 
    return 0;
}

void on_window_main_destroy()
{
    gtk_main_quit();
}

 

 

(4)編譯並執行成功

treehrt@treehrt-fire:~/mysqlc$ gcc gtk5.c -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic

(5)REF:

https://prognotes.net/2015/06/gtk-3-c-program-using-glade-3/

 

迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType