当前位置:网站首页>第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 underlying data structure ----quicklist
- 母婴用品批发行业使用管理软件提高效率 实现降本增效
- Edge浏览器使用BdTab新标签页插件(BD新标签页)
- 24 | adventure and prediction (III): thread pool in CPU
- 21 | 面向流水线的指令设计(下):奔腾4是怎么失败的?
- Create a substrate private network
- Redis master-slave replication - underlying principle
- 21 | pipeline oriented instruction design (Part 2): How did Pentium 4 fail?
- Redis interview questions
- Tidb certification guide PCTA Pctp
猜你喜欢
Edge浏览器如何安装BdTab(BD)新标签页插件(图文教程)
ERP基础数据 华夏
19 | 建立数据通路(下):指令+运算=CPU
C盘爆满?简单几招教你释放、清理C盘几十G空间,最有效的C盘清理方法
The way of distributed system: Lamport logical clock
中小型照明灯饰行业如何利用数字化转型突出重围?
ERP基础数据 金蝶
Redis underlying data structure ----quicklist
【PYTORCH】Expected object of type torch. xxxTensor but found type torch. cuda. xxxTensor(torch0.4.0)
6. fabric2.2 stop clustering and delete data (use the official demo)
随机推荐
Tidb certification guide PCTA Pctp
A troubleshooting process for database timeout caused by SQL misguided
uniapp 小程序根据权限动态生成 tabbar
Get properties of class
Free file server storage technology
Effective Go - The Go Programming Language
ERP基础数据 金蝶
【PYTORCH】Expected object of type torch. xxxTensor but found type torch. cuda. xxxTensor(torch0.4.0)
Redis interview questions
18 | 建立数据通路(中):指令+运算=CPU
Selenium reports an error deprecationwarning: executable_ path has been deprecated, please pass in a Service object
JMeter common commands
汽配行业面临的难题用什么软件帮忙解决呢
Install cuda+cusp environment and create the first helloword starter project
钉钉小程序 父子传参数对象 子组件页面不更新?
3. deploy the fabric2.2 cluster (use the official demo)
2022 simulated examination question bank and online simulated examination of hoisting machinery command examination questions
25 | 冒险和预测(四):今天下雨了,明天还会下雨么?
OpenHarmony笔记-----------(一)
Remote office solution under epidemic situation