|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Gtk closeing windows
hey i am new to gtk programming, i am working on some simple practice code, so far i have a window with a table that has a label and then 2 buttons. one button quits the app completely. the other button makes an about like window that has a label and a close button. the close button is linked to delete_event but return false doesnt close that window, cant do gtk_main_quit because that will close the whole app not just the about window. i also tried another one earlier which i think was gtk_destroy(window) or something of the sort but in the delete_event function window would be undefined so that didnt work.
anyone can help me? should i post what i have so far? |
|
#2
|
||||
|
||||
|
We'll need to see some code.
I can't quite follow what you're saying. your code should explain.
__________________
~James [Not currently seeking freelance work] Like philosophy or interested in spirituality? Philosophorum. Game Dev Experts Forums Foresight Linux - Because your desktop should be cool! Linux FAQ FedoraFAQ UbuntuGuide |
|
#3
|
|||
|
|||
|
thanks
#include <gtk/gtk.h>
static gboolean delete_event( GtkWidget *widget, GdkEvent *event, gpointer data ) { /*HERE I NEED SOMETHING TO CLOSE THE ABOUT WINDOW WHEN THE BUTTON IS PUSHED, I CANT USE GTK_DESTROY(WINDOW) BECAUSE WINDOW IS NOT DEFINED IN THIS FUNCTION*/ return FALSE; } static void destroy( GtkWidget *widget, gpointer data ) { gtk_main_quit (); } static gboolean about( GtkWidget *widget, GdkEvent *event, gpointer data ) { GtkWidget *window; GtkWidget *button; GtkWidget *table; GtkWidget *frame; GtkWidget *label; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "About"); g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (delete_event), NULL); frame = gtk_frame_new ("About"); label = gtk_label_new ("This is a label without autowrap text"); button = gtk_button_new_with_label ("close"); /* THIS IS THE BUTTON THAT WHEN PRESSED I WANT IT TO CLOSE THIS "ABOUT" WINDOW WITHOUT CLOSING THE ENTIRE PROGRAM, THIS BUTTON ACTIVATES delete_event BUT THAT DOESNT CLOSE THE ABOUT WINDOW */ g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (delete_event), NULL); table = gtk_table_new (2, 3, TRUE); gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, 1, 2); gtk_container_add (GTK_CONTAINER (frame), label); gtk_table_attach_defaults (GTK_TABLE (table), frame, 0, 3, 0, 1); gtk_container_add (GTK_CONTAINER (window), table); gtk_widget_show (label); gtk_widget_show (frame); gtk_widget_show (button); gtk_widget_show (table); gtk_widget_show (window); } int main( int argc, char *argv[] ) { GtkWidget *window; GtkWidget *button; GtkWidget *table; GtkWidget *frame; GtkWidget *label; gtk_init (&argc, &argv); frame = gtk_frame_new ("DATA"); label = gtk_label_new ("This is a label without autowrap text"); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "Application Name"); g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (delete_event), NULL); gtk_container_set_border_width (GTK_CONTAINER (window), 10); table = gtk_table_new (2, 2, TRUE); gtk_container_add (GTK_CONTAINER (window), table); button = gtk_button_new_with_label ("About"); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (about), (gpointer) "About"); gtk_container_add (GTK_CONTAINER (frame), label); gtk_table_attach_defaults (GTK_TABLE (table), frame, 0, 2, 0, 1); gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 1, 1, 2); gtk_widget_show (button); button = gtk_button_new_with_label ("Quit"); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (destroy), NULL); gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, 1, 2); gtk_widget_show (button); gtk_widget_show (label); gtk_widget_show (frame); gtk_widget_show (table); gtk_widget_show (window); gtk_main (); return 0; } |
|
#4
|
||||
|
||||
|
Can you please point out the lines of code you're having trouble with and why you think that is?
|
|
#5
|
|||
|
|||
|
(line numbers have changed a bit because of the new commenting)
i need line 11 to close the window made by the about function (line 21) without closeing the entire application (dont want to use gtk_main_quit) maybe on line 34 something needs to be changed in the signal for the button that when pressed will call the delete_event function (line 4) i also did a bit of commenting there too to explain the problem. thanks for the help. |
|
#6
|
||||
|
||||
|
Right, I see what you're on with.
The only way out of this one that I can see is a global variable, which I use for all my windows anyway. So declare window globally at the top of the file. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Other Programming Languages > Gtk closeing windows |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|