如何从GTK spinbutton中检索输入值为float?

时间:2015-09-04 18:18:47

标签: c user-interface input gtk3 gnome

我是编程以及GTK的新手,我想为我的圆锥方程式程序创建一个GUI。

如何从旋转按钮检索输入为浮动?

void lineG_popup_clicked (GtkButton* button, GtkWidget*){
GtkWidget *popup_window, *button1, *box;
GtkWidget *table,*label,*entry, *entry1, *label1, *label3, *label2, *entry2;
GtkAdjustment *adjustment;


popup_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (popup_window), "Line general formula");
gtk_container_set_border_width (GTK_CONTAINER (popup_window), 10);
gtk_window_set_resizable (GTK_WINDOW (popup_window), FALSE);
gtk_widget_set_size_request (popup_window, 150, 100);

box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (popup_window), box);
label = gtk_label_new ("Line general formula general:(y = a*x + b )");
gtk_container_add (GTK_CONTAINER (box), label);
table = gtk_table_new(4, 2, TRUE);
gtk_container_add (GTK_CONTAINER (box), table);

adjustment = gtk_adjustment_new (0, 0.0, 10.0, 0.5, 0.1, 0.0);
entry = gtk_spin_button_new(adjustment,1,2);
gtk_table_attach_defaults (GTK_TABLE (table), entry, 1, 2, 1, 2);

label1 = gtk_label_new ("Input the value of a:");
gtk_table_set_homogeneous(GTK_TABLE (table), TRUE);
gtk_table_attach_defaults(GTK_TABLE (table), label1, 0, 1, 1, 2);

adjustment = gtk_adjustment_new (0, 0.0, 10.0, 0.5, 0.1, 0.0);
entry1 = gtk_spin_button_new(adjustment,1,2);
gtk_table_attach_defaults(GTK_TABLE(table), entry1, 1, 2, 2, 3);

label2=gtk_label_new("Input the value of b:");
gtk_table_set_homogeneous(GTK_TABLE(table), TRUE);
gtk_table_attach_defaults(GTK_TABLE (table), label2, 0, 1, 2, 3);

button1 = gtk_button_new_with_label("OK");
gtk_table_set_homogeneous(GTK_TABLE(table), TRUE);
gtk_table_attach_defaults(GTK_TABLE (table), button1, 1, 2, 3, 4);

gtk_widget_show_all (popup_window);
gtk_widget_grab_focus (popup_window);
}

1 个答案:

答案 0 :(得分:0)

gdouble val = gtk_spin_button_get_value(entry);

那应该为你做!我发现API docs非常有帮助,因为我刚刚开始使用GTK +