最近尝试了多种linux下的GUI编程方法,包括:

1. TkInter (基于Python语言)
在Ubuntu下需要安装Python-tk。简单的例子如下:
----------------------------------------------------
#!/usr/bin/env python

from Tkinter import *

root = Tk()

minutes = Label(root, text="Minutes:")
minutes.pack(side = LEFT)

scale = Scale(root, from_=1, to=45, orient=HORIZONTAL, length=300)
scale.pack()

button = Button(root, text="Start timing", command=quit)
button.pack(side="left")

root.mainloop()
----------------------------------------------------
保存上述程序为文件如eggtimer, 在命令行下运行$ python eggtimer,可以看到GUI的窗口。

但是,深入的学习应该从Python开始。Python编程发张迅速,因为简单,清晰易学以及大量的库存在而有助于快速的市场响应。

2. wxWidgets (基于图形库)
程序例子见:http://www.wxwidgets.org/docs/tutorials/hworld.txt
关于该程序的描述见:http://www.wxwidgets.org/docs/tutorials/hello.htm
安装方法如下:
$apt-get install libwxgtk2.8-dev libwxgtk2.8-dbg
编译: $wx-config --cxxflags | xargs g++ -c helloworld.cpp
链接:$wx-config --libs | xargs g++ -o helloworld helloworld.o
进一步的学习应该参考wxWidgets的网站和好的书籍。

3. GTK (GIMP Toolkit)
GIMP - GNU Image Manipulation Program
GTK, 是用于创建用户图形界面的库,采用LGPL license。
使用GTK需要安装,libgtk2.0-dev,下面是一个例程以及编译方法:
----------------------------------------------------
#include <gtk/gtk.h>

int main( int   argc,
char *argv[] )
{
GtkWidget *window;

gtk_init (&argc, &argv);

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show  (window);

gtk_main ();

return 0;
}
----------------------------------------------------
编译方法:
$pkg-config --cflags gtk+-2.0 | xargs gcc -Wall -g -c helloworld.c
$pkg-config --libs gtk+-2.0 | xargs gcc -o helloworld helloworld.o

4. Qt (cute)
跨平台应用程序开发构架。
安装qt3-dev-tools ... ...未尝试...

附:
GPL和LGPL原文相当繁琐,网上有一些好的阐述方便我们的理解:
<<GPL和LGPL>>
http://kang.javaeye.com/blog/429514
<<关于GPL和LGPL>>
http://blog.csdn.net/flowingflying/archive/2010/03/16/5386069.aspx
<<The differences between the GPL, LGPL and the BSD>>
http://fosswire.com/post/2007/04/the-differences-between-the-gpl-lgpl-and-the-bsd/

Linux GUI编程
标签: