gtk窗口和标签控件范例代码
Posted 柳鲲鹏泰山
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gtk窗口和标签控件范例代码相关的知识,希望对你有一定的参考价值。
其实已有此类博文。标题不够清楚,编译脚本也没找到。
- 安装依赖库
sudo apt install -y libgtk2.0-dev
- 源码
#include <gtk/gtk.h>
#define FIRST_LABEL "first label"
int main(int argc, char *argv[])
gtk_init(NULL, NULL);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
GtkWidget *vbox = gtk_vbox_new(TRUE, 10);
gtk_container_add(GTK_CONTAINER(window), vbox);
GtkWidget *label_one = gtk_label_new(FIRST_LABEL);
gtk_container_add(GTK_CONTAINER(vbox), label_one);
gtk_widget_show_all(window);
gtk_main();
return 0;
- 编译脚本
#!/bin/bash
COMPILE_INCLUDE=$COMPILE_INCLUDE" -I/usr/include/gtk-2.0"
COMPILE_INCLUDE=$COMPILE_INCLUDE" -I/usr/include/glib-2.0"
COMPILE_INCLUDE=$COMPILE_INCLUDE" -I/usr/include/pango-1.0"
COMPILE_INCLUDE=$COMPILE_INCLUDE" -I/usr/include/cairo"
COMPILE_INCLUDE=$COMPILE_INCLUDE" -I/usr/include/gdk-pixbuf-2.0"
COMPILE_INCLUDE=$COMPILE_INCLUDE" -I/usr/include/atk-1.0"
COMPILE_INCLUDE=$COMPILE_INCLUDE" -I/usr/include/harfbuzz"
COMPILE_INCLUDE=$COMPILE_INCLUDE" -I/usr/lib/x86_64-linux-gnu/glib-2.0/include"
COMPILE_INCLUDE=$COMPILE_INCLUDE" -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include"
COMPILE_LINK=$COMPILE_LINK" -lgobject-2.0 -lgtk-x11-2.0"
OUTPUT_FILE=test
if [ -f $OUTPUT_FILE ]; then
rm $OUTPUT_FILE
fi
echo $COMPILE_INCLUDE_LINK
gcc \\
-o $OUTPUT_FILE \\
gtk.cpp \\
$COMPILE_INCLUDE \\
$COMPILE_LINK
以上是关于gtk窗口和标签控件范例代码的主要内容,如果未能解决你的问题,请参考以下文章