PathEntry
Bases: Field
A path entry field widget with file/directory chooser dialog button.
PathEntry extends the Field widget to provide a specialized input for file and directory paths. It includes a button that opens a native file/directory chooser dialog, and displays the selected path(s) in the entry field. The widget supports various dialog types including single file selection, multiple file selection, directory selection, and save file dialogs.
Events
<<Change>>: Fired when a path is selected from the dialog.
Provides event.data with keys: value, prev_value, text, dialog_result.
<<Input>>: Fired when user manually types in the entry.
<<Valid>>: Fired when validation passes.
<<Invalid>>: Fired when validation fails.
Attributes:
| Name | Type | Description |
|---|---|---|
entry_widget |
TextEntryPart
|
The underlying text entry widget. |
label_widget |
Label
|
The label widget above the entry (from FieldOptions). |
message_widget |
Label
|
The message label widget below the entry. |
addons |
dict[str, Widget]
|
Dictionary of inserted addon widgets by name. |
variable |
Variable
|
Tkinter Variable linked to entry text. |
signal |
Signal
|
Signal object for reactive updates. |
dialog_result |
Any
|
The raw result from the last file dialog operation. |
dialog_button |
Button
|
The button widget that opens the dialog. |
dialog_button
property
dialog_button
Get the dialog button widget.
dialog_result
property
dialog_result
Get the raw result from the last file dialog operation.
For single file selection, this returns the path string. For multiple file selection, this returns a tuple/list of paths.
__init__
__init__(
master: Master = None,
*,
value: str | None = None,
dialog: FileDialogType = "openfilename",
dialog_options: dict[str, Any] | None = None,
button_text: str = "Browse",
label: str = None,
message: str = None,
**kwargs: Unpack[FieldOptions],
)
Initialize a PathEntry widget.
Creates a path entry field with a button that opens a native file or directory chooser dialog. The selected path(s) are automatically displayed in the entry field. The widget supports various dialog types for different use cases (single file, multiple files, directory, save file).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
master
|
Master
|
Parent widget. If None, uses the default root window. |
None
|
value
|
str | None
|
Initial path value to display in the entry field. Default is None (empty field). This is updated when a path is selected from the dialog. |
None
|
dialog
|
FileDialogType
|
Type of file dialog to open. Default is "openfilename". Options:
|
'openfilename'
|
dialog_options
|
dict[str, Any] | None
|
Dictionary of options to pass to the file dialog. Common options: title, initialdir, initialfile, filetypes, defaultextension, multiple. |
None
|
button_text
|
str
|
Text to display on the browse button. Default is "Browse".
Can be changed at runtime via |
'Browse'
|
label
|
str
|
Label text to display above the entry field (from FieldOptions). |
None
|
message
|
str
|
Message text to display below the field. |
None
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
required |
bool
|
If True, field cannot be empty. |
accent |
str
|
Accent token for the focus ring and active border. |
allow_blank |
bool
|
Allow empty input. |
cursor |
str
|
Cursor style when hovering. |
font |
str
|
Font for text display. |
foreground |
str
|
Text color. |
initial_focus |
bool
|
If True, widget receives focus on creation. |
justify |
str
|
Text alignment. |
show_message |
bool
|
If True, displays message area. |
padding |
str
|
Padding around entry widget. |
takefocus |
bool
|
If True, widget accepts Tab focus. |
textvariable |
Variable
|
Tkinter Variable to link with text. |
textsignal |
Signal
|
Signal object for reactive updates. |
width |
int
|
Width in characters. |
Note
When multiple files are selected (using 'openfilenames' or 'openfiles'),
the paths are joined with ", " (comma-space) and displayed in the entry.
The raw dialog result (tuple/list) is available via the dialog_result
property.