| |||||
Main Download Documentation Screenshots |
What is PHP/TK ?PHP/TK is an native extension for the PHP programming language that implements language bindings for TCL/TK. It provides an object-oriented interface and greatly simplifies writing client-side cross-platform GUI applications.The Tk extention functions currently only on Unix systems. To use it, you need to have Tk installed on your system. Tk is very well documented, so we won't waste time here by delving too deeply into Tk itself, but instead concentrate on how to access Tk features from PHP. The binding we use is closest to the Perl binding, so you can use the documentation of PERL/TK to help you. - Let us see some examples of use now. Simple Tk ApplicationA simple Tk application in PHP could resemble this:
Then we use the wmtitle() function of this class to allot a name to the window. This being made, we make a label widget as a child of the root frame, with the option -text which has as a value "Hello World". To note that, it is imperative to delimit the character strings allotted to the options, by { } or " ". In short, to finish, we use the pack() function on the widget "label", in order to place it in the window. The tk_mainloop() function generate the main GUI event loop, it is essential. WidgetsCreating widgets is easy. Take the name of the widget as given in the Tk documentation.You create an instance of a widget using new, just as you would any other object. If you don't specify a parent for a given widget, it will default to the root-level frame. We also need to be able to get information back from our widgets while our program is running by setting up callbacks and sharing data. Setting widget optionIf you look at a Tk reference manual, you'll notice that options for widgets are usually listed with a hyphen as a command-line option might be. That functions in the same way with PHP/TK.
Return valuesTo the creation of a widget or the execution of a function on this one, a value is turned over.
- An error is returned when the creation of a widget failed. The program is then stopped. - An error is returned when a function of the widget failed. The program continues its execution. - An string is returned when the function succeeded. This string is empty if the function does not turn over anything. Binding eventsOur hands can produce events that we can capture. To react to these events, functions of callback are used.
The second parameter of the function tk_callback is equivalent to the first parameter of the call procedure.
Objects by parameterThe objects can be passed in parameter, several solutions are offered to you:
Character stringsThe character strings passed to the functions tk must be treated with greatest severity.On the one hand, they must be delimited by the characters ", or { }. And also that the special characters are preceded by a backslash.
ConclusionTo help you, I advise you to juggle between the Tk manual ( http://www.tcl.tk/man/tcl8.5/TkCmd/contents.htm) and the list of the prototypes contained in the documentation page. |
|||||||