樹心幽徑

« 20180610在ubuntu用c在mysql ilvssell資料庫建立資料表new_id_reg | Main | 20180612在GTK視窗顯示影像並偵測滑鼠按鍵位置(gtk8.c) »

20180611在GTK視窗上建立二個Widget控制項(一個text,一個label或二個label)
2018/06/11,20:54

(1)

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ cat gtk6.c
//https://raw.githubusercontent.com/staalmannen/gqt/master/examples/textarea.c

#include <gtk/gtk.h>
int main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *text;
  GtkWidget *label;

  gtk_init (&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);


  GtkWidget *button_box;
  button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  gtk_container_add (GTK_CONTAINER (window), button_box);

  label = gtk_label_new("一首詩");
  gtk_container_add (GTK_CONTAINER (button_box), label);

  text = gtk_text_view_new();
  gtk_text_view_set_editable(GTK_TEXT_VIEW (text), TRUE);
  gtk_container_add (GTK_CONTAINER (button_box), text);

  GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW (text));
  gtk_text_buffer_set_text(buf,  "會活就會活,會死就會死,一切活該到楣,也幸福快樂。", -1);

  gtk_window_set_default_size (GTK_WINDOW(window), 320, 160);

  gtk_window_set_title(GTK_WINDOW (window), "Text文字盒與Label標籤");

  gtk_widget_show_all (window);

  gtk_main();

  return 0;
}

(2)

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ gcc gtk6.c -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ ./a.out &

 

(3)

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ cat gtk7.c
//REF: https://raw.githubusercontent.com/staalmannen/gqt/master/examples/label.c
//https://www.cc.gatech.edu/data_files/public/doc/gtk/tutorial/gtk_tut.html#toc4
#include <gtk/gtk.h>
int main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *label1;
  GtkWidget *label2;

  gtk_init (&argc, &argv);
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
  GtkWidget *button_box;
  button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  gtk_container_add (GTK_CONTAINER (window), button_box);

  label1 = gtk_label_new("大悲無言");
  label2 = gtk_label_new("大智若愚");
  gtk_container_add(GTK_CONTAINER (button_box), label1);
  gtk_container_add(GTK_CONTAINER (button_box), label2);

  gtk_window_set_default_size (GTK_WINDOW(window), 320, 160);

  gtk_window_set_title(GTK_WINDOW (window), "Label標籤*2");

  gtk_widget_show_all (window);

  gtk_main();

  return 0;
}

(4)

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ gcc gtk7.c -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic
treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/mysqlc$ ./a.out &

 

迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType