What This Example Demonstrates
This example shows how to:- Create different types of buttons
- Attach callback functions to handle button clicks
- Use FLTK’s built-in dialogs and alerts
- Exit an application gracefully
- Trigger system sounds (beep)
Complete Source Code
Source file:test/button.cxx
Compilation Command
Expected Behavior
The program displays a window with three buttons:- Beep - Triggers a system beep sound when clicked
- no op - Does nothing (no callback attached)
- Exit - Closes the application
& character in button labels creates keyboard shortcuts:
- Alt+B for Beep
- Alt+N for “no op”
- Alt+X for Exit
Key Concepts
Button Creation
Fl_Button(x, y, width, height, label)
Callback Functions
Callbacks have this signature:Keyboard Shortcuts
The& character in a label creates an Alt+key shortcut:
"&Beep"→ Alt+B"E&xit"→ Alt+X
System Functions
Variations and Extensions
Using Different Button Types
Passing User Data to Callbacks
Getting Button State
Button Colors and Appearance
Using Dialogs
Next Steps
- Learn about advanced callbacks
- Explore input widgets
- See custom widgets