The FLTK project has excellent documentation. However, it is in C++. Rather than duplicating the documention in Python, it is much easier to simply provide a document translating the existing C++ API to Python.
Since the naming of FLTK classes, functions and constants start with
Fl_Foo (classes)
fl_foo() (functions)
Fl.foo() (functions)
FL_FOO (constants)
It's okay to use:
from fltk import *
However, if you just use
import fltk
Then your code will look like
fltk.Fl_Foo
fltk.fl_foo()
fltk.Fl.foo()
fltk.FL_FOO
which seems unneccesary.
Let's start with Hello.cxx from FLTK Basics
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
int main(int argc, char **argv) {
Fl_Window *window = new Fl_Window(340,180);
Fl_Box *box = new Fl_Box(20,40,300,100,"Hello, World!");
box->box(FL_UP_BOX);
box->labelfont(FL_BOLD+FL_ITALIC);
box->labelsize(36);
box->labeltype(FL_SHADOW_LABEL);
window->end();
window->show(argc, argv);
return Fl::run();
}
This would translate into the code below:
from fltk import *
window = Fl_Window(340,180)
box = Fl_Box(20,40,300,100,"Hello, World!")
box.box(FL_UP_BOX)
box.labelfont(FL_BOLD+FL_ITALIC)
box.labelsize(36)
box.labeltype(FL_SHADOW_LABEL)
window.end()
window.show()
Fl.run()
However, to utilize command line args we would have to import sys
in Python.
Code Translations:
C++ | Python |
---|---|
-> | . |
:: | . |
Notice the initializer/constructor for creating a window:
Fl_Window(int w, int h, const char *title=0)
Fl_Window (int x, int y, int w, int h, const char *title=0)
Like in Python, =0 means the default argument value is 0. So the last arg is optional.
C++ | Python |
---|---|
int | integer |
const char * | string |
0 | None |