How to resolve the algorithm Simple windowed application step by step in the OCaml programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Simple windowed application step by step in the OCaml programming language
Table of Contents
Problem Statement
Create a window that has:
Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Simple windowed application step by step in the OCaml programming language
Source code in the ocaml programming language
#directory "+labltk"
#load "labltk.cma"
let () =
let top = Tk.openTk() in
Wm.title_set top "Tk-OCaml Example";
let label = Label.create ~text:"There have been no clicks yet" top in
let b =
Button.create
~text:"click me"
~command:(fun () -> Tk.closeTk (); exit 0)
top
in
Tk.pack [Tk.coe label; Tk.coe b];
Tk.mainLoop ();
;;
open GMain
let window = GWindow.window ~border_width:2 ()
let vbox = GPack.vbox ~packing:window#add ()
let label = GMisc.label ~text:"There have been no clicks yet" ~packing:vbox#pack ()
let button = GButton.button ~label:"click me" ~packing:vbox#pack ()
let () =
window#event#connect#delete ~callback:(fun _ -> true);
window#connect#destroy ~callback:Main.quit;
button#connect#clicked ~callback:window#destroy;
window#show ();
Main.main ()
You may also check:How to resolve the algorithm Random numbers step by step in the Factor programming language
You may also check:How to resolve the algorithm Munching squares step by step in the Go programming language
You may also check:How to resolve the algorithm Inheritance/Multiple step by step in the C# programming language
You may also check:How to resolve the algorithm Modular exponentiation step by step in the OCaml programming language
You may also check:How to resolve the algorithm Binary digits step by step in the ALGOL 68 programming language