#include <gtk/gtk.h>
GtkBuilder *builder;
GtkWidget *window;
GtkImage *image;
GtkButton *but;
char s[1000];
void on_button1_button_press_event(GtkWidget *but, gpointer data)
{
strcpy(s, "/home/linux/testing2.png");
gtk_widget_queue_draw (image);
}
int main(void)
{
gtk_init(NULL, NULL);
builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "/home/linux/gui.xml", NULL);
window = (GtkWidget *) gtk_builder_get_object(builder, "window1");
image = (GtkImage *) gtk_builder_get_object(builder, "image1");
but = (GtkButton *) gtk_builder_get_object(builder, "button1");
gtk_image_set_from_file(image, strcpy(s, "/home/linux/testing1.png"));
g_signal_connect(but, "clicked", G_CALLBACK(on_button1_button_press_event), NULL);
gtk_widget_show(window);
gtk_main();
return 0;
}
當我點擊「button1」,「callback」函數調用,它更新字符串s然後我想gtk刷新「image1」與gtk_widget_queue_draw。但「image1」沒有改變。C更新GTK3的GUI元素
請發佈代碼,沒有代碼無法幫助。具體顯示文件路徑更改後究竟調用了什麼,以及您嘗試執行的操作不起作用。原則上,您可以爲此調用[gtk_widget_queue_draw()](https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-queue-draw),但在實踐中,如果您設置了新圖像這個函數應該被自動調用。 –
謝謝你的回覆。我發佈了我的示例代碼。 –