Linux图形界面编程简单教程(附计算器源代码)
2012-12-16 19:44
281 查看
如何在linux下用gtk开发图形界面应用程序
最近爱上了Linux,尤其是在读了我博客转载到一篇文章之后,更加的决定这辈子要和linux做永远的情人。正好博主这学期也学习了Linux操作系统。当然了,在大学里就是随便的教教,我们也在下边随便的打打酱油而已。前天突然心血来潮,何不做一个图形界面的程序来练练手。说做就做,先声明,本人菜鸟,所以这个过程十分的漫长,花了整整一天的时间。
首先,就是搭建gtk开发环境。光是熟悉这个概念就用了好长时间。你可以自己百度或着查阅相关资料。这里我也推荐一些比较好的博文给大家。
http://wenku.baidu.com/view/f996fa563c1ec5da50e27099.html
我使用的是ubuntu,默认的是gnome,装gtk的时候可是花费了不少时间,因为老是提示说依赖关系不正确而安装不了开发环境。后来在一个博客上找到了解决方法,现在分享给大家。如果提示下面到问题:
下列软件包有未满足的依赖关系:
gnome-devel: 依赖: libgdl-1-dev (>= 2.28) 但是它将不会被安装
推荐: gnome-core-devel 但是它将不会被安装
E: 破损的软件包
那么可以使用下面到命令:
sudo aptitude install gnome-core-devel
http://blog.sina.com.cn/s/blog_3fbc1c610100lf91.html
安装好程序后,下面是计算器的源码:
glade_counter.c
View Code
编译命令makefile:
glade界面设计大师截图:
程序运行截图:
最近爱上了Linux,尤其是在读了我博客转载到一篇文章之后,更加的决定这辈子要和linux做永远的情人。正好博主这学期也学习了Linux操作系统。当然了,在大学里就是随便的教教,我们也在下边随便的打打酱油而已。前天突然心血来潮,何不做一个图形界面的程序来练练手。说做就做,先声明,本人菜鸟,所以这个过程十分的漫长,花了整整一天的时间。
首先,就是搭建gtk开发环境。光是熟悉这个概念就用了好长时间。你可以自己百度或着查阅相关资料。这里我也推荐一些比较好的博文给大家。
http://wenku.baidu.com/view/f996fa563c1ec5da50e27099.html
我使用的是ubuntu,默认的是gnome,装gtk的时候可是花费了不少时间,因为老是提示说依赖关系不正确而安装不了开发环境。后来在一个博客上找到了解决方法,现在分享给大家。如果提示下面到问题:
下列软件包有未满足的依赖关系:
gnome-devel: 依赖: libgdl-1-dev (>= 2.28) 但是它将不会被安装
推荐: gnome-core-devel 但是它将不会被安装
E: 破损的软件包
那么可以使用下面到命令:
sudo aptitude install gnome-core-devel
http://blog.sina.com.cn/s/blog_3fbc1c610100lf91.html
安装好程序后,下面是计算器的源码:
glade_counter.c
View Code
<?xml version="1.0"?> <interface> <requires lib="gtk+" version="2.16"/> <!-- interface-naming-policy project-wide --> <object class="GtkWindow" id="window"> <signal name="destroy" handler="gtk_main_quit"/> <signal name="delete_event" handler="gtk_main_quit"/> <child> <object class="GtkVBox" id="vbox"> <property name="visible">True</property> <property name="spacing">2</property> <child> <object class="GtkVBox" id="vbox1"> <property name="visible">True</property> <child> <object class="GtkLabel" id="label1"> <property name="visible">True</property> <property name="label" translatable="yes">李小超版权所有 网站:www.leeinn.info</property> </object> <packing> <property name="position">0</property> </packing> </child> <child> <object class="GtkHBox" id="hbox1"> <property name="visible">True</property> <child> <object class="GtkEntry" id="entry"> <property name="width_request">200</property> <property name="height_request">40</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="invisible_char">●</property> </object> <packing> <property name="position">0</property> </packing> </child> <child> <object class="GtkButton" id="button1"> <property name="label" translatable="yes">CE</property> <property name="width_request">20</property> <property name="height_request">20</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="position">1</property> </packing> </child> </object> <packing> <property name="position">1</property> </packing> </child> </object> <packing> <property name="position">0</property> </packing> </child> <child> <object class="GtkTable" id="table"> <property name="visible">True</property> <property name="n_rows">4</property> <property name="n_columns">4</property> <property name="column_spacing">2</property> <property name="row_spacing">2</property> <child> <object class="GtkButton" id="button2"> <property name="label" translatable="yes">7</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> </child> <child> <object class="GtkButton" id="button3"> <property name="label" translatable="yes">8</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> </packing> </child> <child> <object class="GtkButton" id="button4"> <property name="label" translatable="yes">9</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="left_attach">2</property> <property name="right_attach">3</property> </packing> </child> <child> <object class="GtkButton" id="button5"> <property name="label" translatable="yes">+</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="left_attach">3</property> <property name="right_attach">4</property> </packing> </child> <child> <object class="GtkButton" id="button6"> <property name="label" translatable="yes">4</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="top_attach">1</property> <property name="bottom_attach">2</property> </packing> </child> <child> <object class="GtkButton" id="button7"> <property name="label" translatable="yes">5</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> <property name="top_attach">1</property> <property name="bottom_attach">2</property> </packing> </child> <child> <object class="GtkButton" id="button8"> <property name="label" translatable="yes">6</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="left_attach">2</property> <property name="right_attach">3</property> <property name="top_attach">1</property> <property name="bottom_attach">2</property> </packing> </child> <child> <object class="GtkButton" id="button9"> <property name="label" translatable="yes">-</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="left_attach">3</property> <property name="right_attach">4</property> <property name="top_attach">1</property> <property name="bottom_attach">2</property> </packing> </child> <child> <object class="GtkButton" id="button12"> <property name="label" translatable="yes">1</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="top_attach">2</property> <property name="bottom_attach">3</property> </packing> </child> <child> <object class="GtkButton" id="button11"> <property name="label" translatable="yes">2</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> <property name="top_attach">2</property> <property name="bottom_attach">3</property> </packing> </child> <child> <object class="GtkButton" id="button13"> <property name="label" translatable="yes">*</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="left_attach">3</property> <property name="right_attach">4</property> <property name="top_attach">2</property> <property name="bottom_attach">3</property> </packing> </child> <child> <object class="GtkButton" id="button14"> <property name="label" translatable="yes">0</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="top_attach">3</property> <property name="bottom_attach">4</property> </packing> </child> <child> <object class="GtkButton" id="button15"> <property name="label" translatable="yes">.</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> <property name="top_attach">3</property> <property name="bottom_attach">4</property> </packing> </child> <child> <object class="GtkButton" id="button16"> <property name="label" translatable="yes">=</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="left_attach">2</property> <property name="right_attach">3</property> <property name="top_attach">3</property> <property name="bottom_attach">4</property> </packing> </child> <child> <object class="GtkButton" id="button17"> <property name="label" translatable="yes">/</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="left_attach">3</property> <property name="right_attach">4</property> <property name="top_attach">3</property> <property name="bottom_attach">4</property> </packing> </child> <child> <object class="GtkButton" id="button10"> <property name="label" translatable="yes">3</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </object> <packing> <property name="left_attach">2</property> <property name="right_attach">3</property> <property name="top_attach">2</property> <property name="bottom_attach">3</property> </packing> </child> </object> <packing> <property name="position">1</property> </packing> </child> </object> </child> </object> </interface>
编译命令makefile:
CC = gcc all: $(CC) `pkg-config --cflags --libs gtk+-2.0` -export-dynamic glade_counter.c -o glade_counter clean: rm -f glade_counter
glade界面设计大师截图:
程序运行截图:
相关文章推荐
- Linux图形界面编程简单教程(附计算器源代码)
- Linux串口编程教程——串口编程详解(源代码)
- UNIX-LINUX编程实践教程->第八章->实例代码注解->写一个简单的shell->在shell中启动另一个程序
- UNIX-LINUX编程实践教程->第八章->实例代码注解->写一个简单的shell
- C/C++ socket编程教程之二:一个简单的Linux下的socket程序
- 最新linux 编程视频教程下载
- Linux下简单的多线程编程--线程池的实现
- C#基础视频教程4.2 如何编写简单的计算器
- linux下简单源代码包(.tar.gz)的制作
- LinuxC/C++编程基础(23) 使用thrift/rpc开发简单实例(续1)
- linux后台服务编程简单样例
- Linux操作系统下串口编程入门教程
- Flask在linux系统下环境的离线搭建及简单实用教程
- Linux的Makefile简单实例教程
- Unix/Linux环境C编程入门教程(12) openSUSECCPP以及Linux内核驱动开发环境搭建
- UNIX-LINUX编程实践教程->第五章->实例代码注解->echostate.c
- 《UNIX 环境高级编程》源代码在linux环境运行方法
- gtk教程 linux界面编程
- GNU_linux编程指南读书笔记7--比较和合并源代码
- Linux Socket编程简单实例