CTkEntry widget with provision to add short information, warning, and error messages below the widget.
Table of Contents
- Set default messages
- Show information, warning, errors
- Set timeout for errors and warnings
- Chain multiple messages
pip3 install ctkentrymsg
entry = CTkEntryMsg(root,...)
from ctkentrymsg import CTkEntryMsg
from customtkinter import CTk, CTkLabel
root = CTk()
root.title('CTkEntryMsg Example')
CTkLabel(root, text='Username', width=100).grid(
row=0, column=0, sticky='nw', padx=(2,0), pady=(10,0))
username = CTkEntryMsg(
root,
default_msg='* letter,digits, special chars (min 8 chars)',
msg_default_color='blue',
highlight=True,
width=300)
username.grid(row=0, column=1, sticky='ne', pady=(5,0), padx=(0,5))
# showing an error
username.showerror(msg='Username cannot be blank')
root.mainloop()
Output:
| Argument | Description |
|---|---|
| master | root, tkinter.Frame or CTkFrame |
| default_msg | optional default message to show under Entry widget |
| msg_default_color | default message text color. Defaults to #000000 |
| msg_warn_color | message text color for warnings. Defaults to #FC8309 |
| msg_error_color | message text color for errors. Defaults to #FC0909 |
| msg_font: tuple | message font. Defaults to ('Arial', 12) |
| msg_pos (str) | place message above or below the entry. Valid values - 'top', 'bottom'. Defaults to 'bottom'. |
| highlight | change entry widget's foreground color on warning or error. Default is True |
| highlight_warn_color | foreground color for entry on warning. Defaults to #FAC36A |
| highlight_error_color | foreground color for entry on error. Defaults to #FF9090 |
| msg_timeout | global message timeout (in milliseconds) for warnings and errors. Defaults to 3000 ms |
| Method | Description |
|---|---|
| .restore_msg() | Restores message to default state |
| .restore_entry() | Restores entry widget to default state |
| .showerror(msg,...) | Displays error |
| .showwarn(msg,...) | Displays warning |
| .msg_queue(messages) | Chains multiple messages |
Inherited methods from CTkEntry widget
Queues the messages and shows them one after another, seperated at an interval specified in
timeout or msg_timeout argument.
entry = CTkEntryMsg(root, width=300)
messages = [
('error', 'An error message', 1000),
('warn', 'A warning message', 1000),
('error', 'Another error')
]
entry.msg_queue(messages)
Keeps the message and the entry widget highlighted even after timeout.
entry = CTkEntryMsg(root, width=300)
entry.showwarn(
msg='This is a warning',
persist_msg: bool = True,
persist_highlight: bool = True)
Set a default timeout or message specific timeout
# timeout for all messages
entry = CTkEntryMsg(root, ..., msg_timeout=2000)
# this error is shown for 2 seconds
entry.showwarn('This is an error')
# this error is shown only for 1 second
entry.showerror('This is an error', timeout=1000)
entry = CTkEntryMsg(
root,
fg_color='black',
text_color='white',
width=300)
You can also use .configure(...)
entry.configure(font=('Arial', 12), width=400,...)
