psychos.gui.Dialog#
- class psychos.gui.Dialog(title='', ok_text='OK', cancel_text='Cancel', ok_button=True, cancel_button=True, theme='clam', main_padding=20, button_padding=5, wraplength=300)[source]#
Bases:
objectA versatile dialog form using Tkinter.
- This dialog can contain:
Interactive fields (Entry or Combobox).
Static labels (added via add_label).
OK and/or Cancel buttons.
- When displayed (via .show()):
Returns a dictionary of field values + {“accepted”: True} if the user presses OK.
Returns None if the user presses Cancel or closes the dialog window.
- Parameters:
title (str, optional) – Title of the dialog window. Defaults to “” (no title).
ok_text (str, optional) – Label for the OK button. Defaults to “OK”.
cancel_text (str, optional) – Label for the Cancel button. Defaults to “Cancel”.
ok_button (bool, optional) – Whether to display the OK button. Defaults to True.
cancel_button (bool, optional) – Whether to display the Cancel button. Defaults to True.
theme (str, optional) – The ttk theme to use. Defaults to “clam”.
main_padding (int, optional) – Padding around the main container. Defaults to 20.
button_padding (int, optional) – Padding around the button area. Defaults to 5.
wraplength (int, optional) – Maximum label width in pixels (wraps text). Defaults to 300.
- __init__(title='', ok_text='OK', cancel_text='Cancel', ok_button=True, cancel_button=True, theme='clam', main_padding=20, button_padding=5, wraplength=300)[source]#
Methods
__init__([title, ok_text, cancel_text, ...])add_field(name[, default, label, format, ...])Add an interactive field (Entry or Combobox) to the form.
add_label(text)Add a static label to the form (useful for headers, instructions, or separators).
show()Display the dialog form and block until the user responds.
- add_field(name, default=None, label=None, format=<class 'str'>, choices=None)[source]#
Add an interactive field (Entry or Combobox) to the form.
- Parameters:
name (str) – Name (key) of the field in the returned data.
default (Any, optional) – Default value for the field. For a text entry, this is inserted as the initial text. For a combo box, it sets the initial selection. Defaults to None.
label (str, optional) – Label to display next to the field. If None, uses name. Defaults to None.
format (Callable, optional) – A function to format/parse the returned value (e.g., int). Defaults to str.
choices (list, optional) – If provided, creates a combo box with these choices instead of a text entry. Defaults to None.