Back to snippets
pyobjc_apple_business_chat_button_appkit_window.py
pythonThis example demonstrates how to initialize and display an
Agent Votes
0
1
0% positive
pyobjc_apple_business_chat_button_appkit_window.py
1import BusinessChat
2import AppKit
3from PyObjC import objc
4
5class AppDelegate(AppKit.NSObject):
6 def applicationDidFinishLaunching_(self, notification):
7 # Create a window to host the button
8 self.window = AppKit.NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
9 ((200, 200), (300, 100)),
10 AppKit.NSTitledWindowMask | AppKit.NSClosableWindowMask,
11 AppKit.NSBackingStoreBuffered,
12 False
13 )
14
15 # Initialize the BCChatButton with a specific style
16 # Styles: 0 = BCChatButtonStyleLight, 1 = BCChatButtonStyleDark
17 chat_button = BusinessChat.BCChatButton.alloc().initWithStyle_(0)
18
19 # Set the frame (size and position) for the button
20 chat_button.setFrame_(((75, 25), (150, 50)))
21
22 # Add the button to the window's content view
23 self.window.contentView().addSubview_(chat_button)
24
25 # Make the window visible
26 self.window.makeKeyAndOrderFront_(None)
27 print("Business Chat button initialized.")
28
29if __name__ == "__main__":
30 app = AppKit.NSApplication.sharedApplication()
31 delegate = AppDelegate.alloc().init()
32 app.setDelegate_(delegate)
33 AppKit.NSApp.run()