-
-
Notifications
You must be signed in to change notification settings - Fork 106
Command Property
Some tk widgets have command properties. These properties accept a function callback that will be called when the user interacts with the widget.
To define a callback for a widget simply enter the name of the function (or method) in the command property editor.
In code, you must call the method connect_callbacks of the builder object, specifying which functions to connect.
You can pass a dictionary of key:value pairs, where the key is the callback name as was specified on the UI definition, and value is the real python function.
Alternatively, you can pass an object with the same method names as defined in the UI file, and the connection will be made automatically.
Configure the callback names in the UI definition:
Set 1° button callback name:
Set 2° button callback name:
Set 3° button callback name:
Example dir: command_properties
File: command_properties.py
...
def on_button1_click():
messagebox.showinfo("Message", "You clicked Button 1")
def on_button2_click():
messagebox.showinfo("Message", "You clicked Button 2")
def on_button3_click():
messagebox.showinfo("Message", "You clicked Button 3")
class MyApplication:
def __init__(self, master=None):
...
# Configure callbacks
callbacks = {
'on_button1_clicked': on_button1_click,
'on_button2_clicked': on_button2_click,
'on_button3_clicked': on_button3_click
}
builder.connect_callbacks(callbacks)
...
Example dir: command_properties
File: command_properties2.py
...
class MyApplication:
def __init__(self, master=None):
...
# Connect method callbacks
builder.connect_callbacks(self)
# define the method callbacks
def on_button1_clicked(self):
messagebox.showinfo('Message', 'You clicked Button 1')
def on_button2_clicked(self):
messagebox.showinfo('Message', 'You clicked Button 2')
def on_button3_clicked(self):
messagebox.showinfo('Message', 'You clicked Button 3')
...
- Requirements
- Installation
- Launch
- Screens:
- Step-by-Step Examples:
- Completed Examples
- Tips
- Additional widget sets
- Known Issues
- FAQ
- Troubleshooting:
- Communicating: