Sur ce site http://www.chabba.de/LinuxAPI.html, vous trouverez de nombreux exemples utilisant gtk avec la version Linux de PureBasic.

Un exemple pris au hasard :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
;==========================================================
; Module/File:     Button_ColorButton.pb
; Function:        Adds ColorButton with color chooser - Linux
; Author:          Omi
; Date:            Nov. 30, 2014
; Version:         0.1
; Target Compiler: PureBasic 5.22/5.30
; Target OS:       (X)ubuntu Ascii/Uni, 32/64
; License:         Free, unrestricted, no warranty
;==========================================================
 
EnableExplicit
 
ImportC ""
	g_signal_connect(*instance, detailed_signal.p-ascii, *c_handler, *data, destroy= 0, flags= 0) As "g_signal_connect_data"
EndImport
 
; Object constants
#MainWin = 0
 
#Text1   = 0
 
#WinX=300
#WinY=200
#WinW=200
#WinH=200
 
Global.i gEvent, gQuit
Global *colorbutton1.GtkWidget
Global color1.GdkColor
 
 
ProcedureC Callback_ColorButtonChanged(*widget.GtkWidget, user_data)
	If *widget= *colorbutton1
		gtk_color_button_get_color_(*widget, @color1)
 		Debug "red   " + Str(color1\red)
 		Debug "green " + Str(color1\green)
 		Debug "blue  " + Str(color1\blue)
 		Debug "pix   " + Str(color1\pixel)
	EndIf
EndProcedure
 
Procedure.i ColorButtonGadget(Gadget, x, y, w, h)
	Protected.i Container= ContainerGadget(Gadget, x, y, w, h, #PB_Container_BorderLess)
	Protected *cbutton= gtk_color_button_new_()
	If Gadget<> #PB_Any : Container= Gadget :EndIf
	gtk_container_add_(GadgetID(Container), *cbutton)
	gtk_widget_show_(*cbutton)
	CloseGadgetList()
	ProcedureReturn *cbutton
EndProcedure
 
If OpenWindow(#MainWin, #WinX, #WinY, #WinW, #WinH, "Add ColorButton", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	TextGadget(#Text1, 5, 10, 100, 22, "change color: ")
	*colorbutton1= ColorButtonGadget(#PB_Any, 105, 5, 50, 36)
 
	g_signal_connect(*colorbutton1, "color-set", @Callback_ColorButtonChanged(), 0)
 
	Repeat
		gEvent= WaitWindowEvent()
 
		Select gEvent
			Case #PB_Event_CloseWindow
				gQuit= #True
 
		EndSelect
 
	Until gQuit
EndIf
Un autre exemple :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
;======================================================================
; Module/File:     Button_AddImage.pb
; Function:        Button: Add loaded or stock-imaged to pb-Button with alignment - Linux
; Author:          Omi
; Date:            Oct. 14, 2014
; Version:         0.3, updt. utf8-handling, activate images in Buttons
; Target Compiler: PureBasic 5.22/5.30
; Target OS:       (X/K)ubuntu 32/64, Ascii/Uni
; License:         Free, unrestricted, no warranty
;======================================================================
 
EnableExplicit
 
ImportC ""
	gtk_button_set_image(*button.GtkButton, *image.GtkWidget)
	gtk_button_set_image_position(*button.GtkButton, position)
	gtk_button_set_label(*button.GtkButton, label.p-utf8)
	gtk_image_clear(*image.GtkWidget)
	gtk_button_set_alignment(*button.GtkButton, xalign.f, yalign.f)
	gtk_image_new_from_stock(stock_id.p-utf8, size)
	gtk_image_new_from_file(filename.p-utf8)
	g_object_set(*object.GObject, property_name.p-utf8, *data, v= 0)
EndImport
 
#MainWin= 0
 
Enumeration
	#myButton1
	#myButton2
	#myButton3
	#myButton4
	#myButton5
EndEnumeration
 
Global.i gEvent, gQuit
Global *image1, *image2, *image3, *image4
 
 
Procedure ButtonImages_Activate(Show)
	g_object_set(gtk_settings_get_default_(), "gtk-button-images", Show, #Null)
EndProcedure
 
Procedure ButtonGadget_AddImage(Gadget, *Pic, Label.s, Alignment)
	gtk_button_set_image(GadgetID(Gadget), *Pic)
	gtk_button_set_label(GadgetID(Gadget), Label)
	gtk_button_set_image_position(GadgetID(Gadget), Alignment)
EndProcedure
 
 
If OpenWindow(#MainWin, #PB_Ignore, #PB_Ignore, 250, 250, "Linux-Test Button with image")
 
	;if icons are not shown, uncomment the following line ...
	; ButtonImages_Activate(#True)
 
	;for loading icons choose your own image-adresses ...
; 	*image1= gtk_image_new_from_file("/home/charly-xubuntu/Programming/PBSource/Icons/Own/Back.png")
; 	*image2= gtk_image_new_from_file("/home/charly-xubuntu/Programming/PBSource/Icons/Own/Find.png")
; 	*image3= gtk_image_new_from_file("/home/charly-xubuntu/Programming/PBSource/Icons/Own/Previous.png")
; 	*image4= gtk_image_new_from_file("/home/charly-xubuntu/Programming/PBSource/Icons/Own/Stop sign.png")
	;or use stock-images ...
	*image1= gtk_image_new_from_stock("gtk-go-back", #GTK_ICON_SIZE_MENU);  #GTK_ICON_SIZE_BUTTON
	*image2= gtk_image_new_from_stock("gtk-find", #GTK_ICON_SIZE_MENU)
	*image3= gtk_image_new_from_stock("gtk-goto-first", #GTK_ICON_SIZE_MENU)
	*image4= gtk_image_new_from_stock("gtk-stop", #GTK_ICON_SIZE_MENU)
 
	ButtonGadget(#myButton1, 5, 5, 200, 30, "   Button with image", #PB_Button_Toggle)
	 ButtonGadget_AddImage(#myButton1, *image1, "1. Button with image", #GTK_POS_LEFT)
	ButtonGadget(#myButton2, 5, 40, 200, 30, "   Button with image")
	 ButtonGadget_AddImage(#myButton2, *image2, "2. Button with image", #GTK_POS_RIGHT)
	ButtonGadget(#myButton3, 5, 75, 200, 50, "   Button with image")
	 ButtonGadget_AddImage(#myButton3, *image3, "3. Button with image", #GTK_POS_TOP)
	ButtonGadget(#myButton4, 5, 130, 200, 50, "   Button with image")
	 ButtonGadget_AddImage(#myButton4, *image4, "4. Button with image", #GTK_POS_BOTTOM)
	ButtonGadget(#myButton5, 5, 185, 200, 50, "Button with alignment", #PB_Button_Right)
 
	gtk_button_set_alignment(GadgetID(#myButton5), 1.0, 1.0);    geht nur über ImportC
 
Else
	End
EndIf
 
Repeat
	gEvent = WaitWindowEvent()
	If EventWindow()= #MainWin
		Select gEvent
			Case #PB_Event_CloseWindow
				gQuit= #True
		EndSelect
	EndIf
Until gQuit
 
;free image-memory...
gtk_image_clear(*image1)
gtk_image_clear(*image2)
gtk_image_clear(*image3)
gtk_image_clear(*image4)
 
End