当前位置:网站首页>第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;
}
效果图如下
边栏推荐
- 中小型照明灯饰行业如何利用数字化转型突出重围?
- JMeter common commands
- 【PYTORCH】RuntimeError: one of the variables needed for gradient computation has been
- 18 | establish data path (middle): instruction + operation =cpu
- 【博弈论-完全信息静态博弈】 Nash均衡的应用
- Cosmos star application case
- JMeter UDP pressure measurement
- Web site access excel in IIS
- 免费文件服务器储存技术
- Redis Cluster - the underlying principle of cluster execution commands
猜你喜欢

22 | 冒险和预测(一):hazard是“危”也是“机”

Redis underlying data structure -- listpack

25 | 冒险和预测(四):今天下雨了,明天还会下雨么?

Clickhouse column basic data type description

Openharmony notes ----------- (I)

Recognition of COVID-19 based on paddlepaddle

MySQL table partitioning

Redis Cluster - the underlying principle of cluster execution commands

【PYTORCH】Expected object of type torch. xxxTensor but found type torch. cuda. xxxTensor(torch0.4.0)

23 | 冒险和预测(二):流水线里的接力赛
随机推荐
[pytorch] pytorch0.4.0 installation tutorial and GPU configuration collection (including test code)
17 | 建立数据通路(上):指令+运算=CPU
Go 接口实现原理【高阶篇】: type _interface struct
22 | 冒险和预测(一):hazard是“危”也是“机”
19 | 建立数据通路(下):指令+运算=CPU
Redis master-slave replication - underlying principle
19 | establish data path (bottom): instruction + operation =cpu
Dfinity (ICP) identity authentication and ledger quick start-3
Data disorder occurs when the n-th row of the subcomponent list generated by V-for is deleted
20 | 面向流水线的指令设计(上):一心多用的现代CPU
Tidb source code series: immersive compilation of tidb
SolidWorks修改工程图中文字字体的方法
Success logarithm of leetcode spells and potions
[an example of MySQL startup error] innodb: failed to create check sector file, errno:13
口碑好的食材配送信息化管理系统怎么样?
JMeter common commands
MySQL: regexp_ replace
2022 electrician (elementary) examination questions and simulation examination
Detailed explanation of digital certificate and Ca
Dfinity (ICP) basic development tutorial-5