当前位置:网站首页>第115页的gtk+编程例子——最简单的进度条2附带使用Anjuta写gtk程序的步骤
第115页的gtk+编程例子——最简单的进度条2附带使用Anjuta写gtk程序的步骤
2022-06-13 08:06:00 【sukida100】
以下gtk+编程例子是来自书籍《实用技术:开发Linux应用——用GTK+和GDK开发Linux图形用户界面应用》第115页的内容——最简单的进度条2附带使用Anjuta写gtk程序的步骤
官方教程网址https://developer-old.gnome.org/gnome-devel-demos/3.38/progressbar.c.html.en
这是最简单的进度条,它的写法和思路更加简洁和不同,代码格式是gtk3.0,很值得借鉴,antuja是类似Visual Studio和codeblocks编程软件,但是antuja只有linux版而没有windows版的
在gtk2.0中window = gtk_window_new (GTK_WINDOW_TOPLEVEL);主窗口右上角的关闭按钮一定要带上关闭的鼠标动作的g_signal_connect (G_OBJECT (window), “destroy”, G_CALLBACK (gtk_main_quit), NULL);
在gtk3.0中window = gtk_application_window_new (app);主窗口右上角的关闭按钮本身带有关闭功能的,不需要加上鼠标动作的
使用Anjuta写gtk程序的步骤
参考以下官方网址有介绍使用anjuta写gtk程序的步骤
https://developer-old.gnome.org/gnome-devel-demos/3.38/image-viewer.c.html.en
Application——编程——Anjuta
文件——新建——项目——选择项目类型为C的GTK+(简单)——右上角的前进——项目名称:ProgressBar5——项目选择不勾选添加国际化,不勾选使用GtkBuilder制作用户界面——前进——应用
在左栏单击progressbar5左边的三角图标——双击main.c——GtkSourceView编辑器,勾选记住此选项——确定
打开以下网址
https://developer-old.gnome.org/gnome-devel-demos/3.38/progressbar.c.html.en
将进度的源代码复制粘贴到main.c中并保存
运行——执行——出现配置项目的对话框,什么也不用修改,直接单击执行——它会自动configure和make然后在新终端运行程序
在openSUSE-Leap-15.3-DVD-x86_64的gnome3.34.7桌面环境下运行Anjuta 3.28.0,以下内容为源代码,没有修改过,主要是加上中文解释
#include <gtk/gtk.h>
static gboolean
fill (gpointer user_data)
{
GtkWidget *progress_bar = user_data;
/* 获取当前进度条的值 */
gdouble fraction;
fraction = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (progress_bar));
/* 每次调用此函数时,将进度条增加10%,标准写法是fraction = fraction + 0.1 缩写为+= 0.1*/
fraction += 0.1;
/* 根据fraction的值设定进度条显示的长度 */
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), fraction);
/* 确保进度条的值保持在1.0以下*/
if (fraction < 1.0)
return TRUE;
return FALSE;
}
static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
GtkWidget *progress_bar;
gdouble fraction = 0.0;
/* 创建具有标题和默认大小的窗口 */
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "ProgressBar Example");
gtk_window_set_default_size (GTK_WINDOW (window), 220, 20);
/* 创建进度条并将其添加到窗口 */
progress_bar = gtk_progress_bar_new ();
gtk_container_add (GTK_CONTAINER (window), progress_bar);
/* 根据fraction的值设定进度条显示的长度,进度条的值必须介于0.0-1.0(含0.0-1.0)之间*/
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), fraction);
/* 每隔500毫秒运行一次fill函数 */
g_timeout_add (500, fill, GTK_PROGRESS_BAR (progress_bar));
gtk_widget_show_all (window);
}
int
main (int argc, char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
效果图如下
边栏推荐
- Redis master-slave replication - the underlying principle of partial resynchronization
- Web site access excel in IIS
- [problem record] json decoder. JSONDecodeError:Extra data: line xxx column xxx(char xxxx)
- Shell script Basics
- 25 | 冒险和预测(四):今天下雨了,明天还会下雨么?
- Get properties of class
- 17 | 建立数据通路(上):指令+运算=CPU
- 口碑好的食材配送信息化管理系统怎么样?
- The uniapp applet dynamically generates tabbar based on permissions
- 2022年电工(初级)考题及模拟考试
猜你喜欢
Redis persistence -- AOF
AcWing 1977. 信息中继(基环树,并查集)
ES6 deleting an attribute of an object
C盘爆满?简单几招教你释放、清理C盘几十G空间,最有效的C盘清理方法
钉钉小程序如何隐藏tab
Create a substrate private network
Openharmony notes ----------- (I)
口碑好的食材配送信息化管理系统怎么样?
【Emgu.CV】Emgu.CV.Example\OCR运行报错System.IO.FileNotFoundException:“未能加载文件或程序集“System.Drawing.Common
Give code vitality -- the way to read code neatly
随机推荐
MySQL summary
Tidb certification guide PCTA Pctp
实践出真知--你的字节对齐和堆栈认知可能是错误的
有什么好的管理软件来解决茶叶批发商面临的难题
汽配行业面临的难题用什么软件帮忙解决呢
【完全信息静态博弈-Nash均衡的特性】
Redis master-slave replication - mentality detection mechanism
mysql面试题
赋予代码生命力--读代码整洁之道
v-for生成的子组件列表删除第n行出现数据错乱问题
5. fabric2.2 installation and submission contract (using official demo)
免费文件服务器储存技术
获取类的属性
MySQL table cache most detailed notes
Did decentralized digital identity
2022 simulated examination question bank and online simulated examination of hoisting machinery command examination questions
【Emgu.CV】Emgu.CV.Example\OCR运行报错System.IO.FileNotFoundException:“未能加载文件或程序集“System.Drawing.Common
Clickhouse column basic data type description
[redis problem] record a big key problem handling
【clickhouse专栏】基础数据类型说明