You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include<gtk/gtk.h>// Callback function for the "Open" buttonvoidopen_button_clicked(GtkWidget*widget, gpointerdata) {
GtkWidget*dialog;
constgchar*selected_folder;
// Create a new file chooser dialogdialog=gtk_file_chooser_dialog_new("Select a Directory",
GTK_WINDOW(data),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
"_Cancel", GTK_RESPONSE_CANCEL,
"_Open", GTK_RESPONSE_ACCEPT,
NULL);
// Show the dialog and wait for a responsegintresponse=gtk_dialog_run(GTK_DIALOG(dialog));
if (response==GTK_RESPONSE_ACCEPT) {
// Get the selected folder pathselected_folder=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
g_print("Selected Folder: %s\n", selected_folder);
// You can use the selected_folder path as needed// For this example, we just print it to the console
}
// Clean up the dialoggtk_widget_destroy(dialog);
}
intmain(intargc, char*argv[]) {
GtkWidget*window;
GtkWidget*button_box;
GtkWidget*open_button;
gtk_init(&argc, &argv);
// Create the main windowwindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "GTK Directory Picker Example");
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
// Create a button box to hold the "Open" buttonbutton_box=gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
gtk_container_add(GTK_CONTAINER(window), button_box);
// Create the "Open" buttonopen_button=gtk_button_new_with_label("Open Directory Picker");
gtk_container_add(GTK_CONTAINER(button_box), open_button);
// Connect the "clicked" signal of the "Open" button to the callback functiong_signal_connect(G_OBJECT(open_button), "clicked", G_CALLBACK(open_button_clicked), window);
// Show all the widgetsgtk_widget_show_all(window);
// Start the GTK main loopgtk_main();
return0;
}