| 1 | #!/usr/bin/python3 |
| 2 | # "$Id: demos.py 531 2019-12-27 12:15:45Z andreasheld $" |
| 3 | # |
| 4 | # Test program for pyFLTK the Python bindings |
| 5 | # for the Fast Light Tool Kit (FLTK). |
| 6 | # |
| 7 | # FLTK copyright 1998-1999 by Bill Spitzak and others. |
| 8 | # pyFLTK copyright 2003 by Andreas Held and others. |
| 9 | # |
| 10 | # This library is free software you can redistribute it and/or |
| 11 | # modify it under the terms of the GNU Library General Public |
| 12 | # License, version 2.0 as published by the Free Software Foundation. |
| 13 | # |
| 14 | # This library is distributed in the hope that it will be useful, |
| 15 | # but WITHOUT ANY WARRANTY without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | # Library General Public License for more details. |
| 18 | # |
| 19 | # You should have received a copy of the GNU Library General Public |
| 20 | # License along with this library if not, write to the Free Software |
| 21 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 22 | # USA. |
| 23 | # |
| 24 | # Please report all bugs and problems to "[email protected]". |
| 25 | # |
| 26 | |
| 27 | |
| 28 | import sys, os |
| 29 | import fltk |
| 30 | |
| 31 | class mybutton(fltk.Fl_Button): |
| 32 | def __init__(self, x,y,w,h,label): |
| 33 | super().__init__(x,y,w,h, label) |
| 34 | self.callback(self.foo) |
| 35 | self.this.disown() |
| 36 | |
| 37 | def foo(self, wid): |
| 38 | print("Button pressed: exit!") |
| 39 | sys.exit() |
| 40 | |
| 41 | class subwindow(fltk.Fl_Gl_Window): |
| 42 | global window |
| 43 | def __init__(self, x,y,w,h): |
| 44 | super().__init__(x,y,w,h, "") |
| 45 | |
| 46 | def draw(self): |
| 47 | pass |
| 48 | |
| 49 | def handle(self, event): |
| 50 | if event == fltk.FL_PUSH: |
| 51 | print("Push event detected: exit!") |
| 52 | sys.exit() |
| 53 | |
| 54 | |
| 55 | return super().handle(event) |
| 56 | |
| 57 | window = fltk.Fl_Double_Window(0, 0, 800, 600, "xxx") |
| 58 | |
| 59 | sw = subwindow(0,0,800,500) |
| 60 | window.resizable(sw) |
| 61 | |
| 62 | mb = mybutton(350,520,100,60, "Exit") |
| 63 | |
| 64 | window.end() |
| 65 | window.show() |
| 66 | |
| 67 | fltk.Fl.run() |
| 68 |