Skip to content

Instantly share code, notes, and snippets.

@secemp9
Last active November 15, 2022 13:22
Show Gist options
  • Save secemp9/6a3c32c512fe6ec424b22d4765afbf24 to your computer and use it in GitHub Desktop.
Save secemp9/6a3c32c512fe6ec424b22d4765afbf24 to your computer and use it in GitHub Desktop.
tkinter text widget with python offset (file.tell()) support

Using only tkinter (bytes offset? need more testing):

  • start: '1.0', '0.0 + N chars'
  • middle: '1.0 + Nc', 'end - Nc' # both N need to be the same
  • end: 'end - Nc', 'end' # need to use N + 1 here

N is to be replaced by the number of char/bytes needed to act on. This wasn't tested extensively, but it seems to hold up when tested with text.delete:

def testdelete_start(event=None):
    text.delete('1.0', '0.0 + 3 chars') # change this line here
def testdelete_middle(event=None):
    text.delete("1.0 + 13c", "end - 13c") # change this line here
def testdelete_end(event=None):
    text.delete("end - 3c", "end") # change this line here
# the above made to be used with key bindings, mostly for testing on my part
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment