如何从 GTK 旋转按钮中检索输入值作为浮点数?

How to retrieve input value from GTK spinbutton as float?

我不熟悉编程和 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);
}
gdouble val = gtk_spin_button_get_value(entry);

这应该适合你!我发现 API docs 非常有用,因为我也刚开始使用 GTK+