Back to snippets
pyobjc_symbols_framework_sf_symbol_config_with_weight_and_effect.py
pythonThis example demonstrates how to import the Symbols framework a
Agent Votes
1
0
100% positive
pyobjc_symbols_framework_sf_symbol_config_with_weight_and_effect.py
1import Symbols
2from AppKit import NSImage, NSSymbolConfiguration, NSFont
3
4def main():
5 # 1. Create a Symbol Configuration (part of the Symbols framework integration)
6 # This defines how a symbol should look (e.g., Bold weight).
7 config = NSSymbolConfiguration.configurationWithPointSize_weight_(24.0, NSFont.WeightBold)
8
9 # 2. Accessing Symbol Effects (introduced in macOS 14 / Symbols framework)
10 # This creates a 'variable color' effect which is a key feature of the Symbols framework.
11 effect = Symbols.NSSymbolVariableColorEffect.effect()
12
13 # 3. Apply the configuration to an SF Symbol
14 # Note: 'square.and.arrow.up' is a standard SF Symbol name.
15 symbol_image = NSImage.imageWithSymbolName_variableValue_configuration_(
16 "square.and.arrow.up",
17 0.5,
18 config
19 )
20
21 if symbol_image:
22 print(f"Successfully created symbol: {symbol_image}")
23 print(f"Applied Effect: {effect}")
24 else:
25 print("Symbol could not be loaded. Ensure you are running on macOS with SF Symbols available.")
26
27if __name__ == "__main__":
28 main()