Skip to content

Commit

Permalink
Add disabled and readonly state cursor for entry type widgets (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
israel-dryer committed Jan 3, 2022
1 parent 3bbb6d0 commit 3672e7d
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/ttkbootstrap/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ def __init__(
self.wait_visibility(self)
self.attributes("-alpha", alpha)

self._apply_entry_type_class_binding()
self._style = Style(themename)


@property
def style(self):
"""Return a reference to the `ttkbootstrap.style.Style` object."""
Expand All @@ -181,6 +183,46 @@ def place_window_center(self):

position_center = place_window_center # alias

def _apply_entry_type_class_binding(self):
self.bind_class(
className="TEntry",
sequence="<Configure>",
func=self._disabled_state_cursor,
add="+"
)
self.bind_class(
className="TSpinbox",
sequence="<Configure>",
func=self._disabled_state_cursor,
add="+"
)
self.bind_class(
className="TCombobox",
sequence="<Configure>",
func=self._disabled_state_cursor,
add="+"
)

def _disabled_state_cursor(self, event):
"""Change the cursor of entry type widgets to 'arrow' if in a disabled
or readonly state."""
try:
widget = self.nametowidget(event.widget)
state = str(widget.cget('state'))
cursor = str(widget.cget('cursor'))
if state in (DISABLED, READONLY):
if cursor == 'arrow':
return
else:
widget['cursor'] = 'arrow'
else:
if cursor in ('ibeam', ''):
return
else:
widget['cursor'] = None
except:
pass


class Toplevel(tkinter.Toplevel):
"""A class that wraps the tkinter.Toplevel class in order to
Expand Down

0 comments on commit 3672e7d

Please sign in to comment.