#Python 3 - Win10
Tkinter Word Processor
Text Widget: Line Wrapping
Find Wrap Position 2
Brief:
_______________________________________________________________
So as it turns out I didn't need to do any of that heavy lifting in my previous post. There were methods in place to do what I wanted. I found the answer in the tkinter/tcl docs while trying to figure out a different problem with the word processor application. I've been using this functions all the time but did not realize I could use the "display" sub-modifier when calling indices. But it's live and learn with coding.The code is so minuscule it makes me want to cry for the time I took brute forcing the functionality.
Functionality:
_______________________________________________________________
...
Improvements:
- N/A
Issues:
- N/A
Demo:
_______________________________________________________________
N/A
Code Snippet:
_______________________________________________________________
import tkinter as tk def inspect_wrapline(event=None): start = f"{tk.INSERT} linestart" end = f"{tk.INSERT} lineend" counter = event.widget.count(start, end, "displaylines") print("number of lines after first line", counter) start = f"{tk.INSERT} display linestart" end = f"{tk.INSERT} display lineend +1c" dline = event.widget.get(start, end) print("Text on the displayline", dline) root_window = tk.Tk() text_widget = tk.Text(root_window) text_widget.pack() text_widget.insert("This is an example text.") text_widget.bind("<Control-l>", inspect_wrapline) root_window.mainloop()
Credits and Resources:
- Code formatted via: http://hilite.me/ : Styling: Python, monokai
- https://tcl.tk/man/tcl8.6/TkCmd/text.htm
- https://tkdocs.com/tmp-pyref/onepage.html
- https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/text-methods.html
- https://docs.python.org/3/library/tkinter.ttk.html
- https://stackoverflow.com/
No comments:
Post a Comment
Conduct: Be nice and don't advertise or plug without adding value to the conversation.