Package: tklinenums
TkLineNumsNoteIf Python was installed via Homebrew, installed on Mac by default, or installed on Linux, tkinter will likely not work properly and may need to be installed viabrew install python-tkor with the distro package manager on Linux as documentedhere.DescriptionTkLineNumsis a simple line numbering widget for Python'stkinterGUI library. It is directly connects to aTextwidget and even supports ttk themes through the set_to_ttk_style method.Features of theTkLineNumswidget:Clicking on line numbers will set the insert to the beginning of the line.Shift clicking will select all text from the end of the line clicked by cursor and the insert position.Scrolling the linebar will scroll the text widget (and vice versa).Can handle elided lines (elided lines are lines that are not visible in the text widget).Supports ttk themes and allows easy color customization.Supports left, right, and center alignment with the-justifyoption.Clicking and then dragging the mouse will scroll the text widget.Supports click dragging for selection.InstallationIn the Command Line, paste the following:pip install tklinenums.DocumentationTkLineNumsWidgetOptionsDescriptionTypemasterThe parent widgetTkinter widget (defaults totkinter.Misc)textwidgetTheTextwidget the line numbers will connect toTkinterTextwidget (or child class)justifyThe alignment of the line numbersA string as either"left","right", or"center"colorsA way to provide coloring to the line numbersA function,(foreground, background)tuple, or None. None (default) makes it use theTextwidget's coloring. The function should return a(foreground, background)tuple: it will be called whenever the colors are needed, and it is useful when the colors can change.*argsArguments for theCanvaswidgetAny arguments used for theCanvaswidget**kwargsKeyword arguments for theCanvaswidgetAny keyword arguments used for theCanvaswidgetBasic Usage:fromtkinterimportText,Tkfromtkinter.ttkimportStylefromtklinenumsimportTkLineNumbers# Create the root windowroot=Tk()# Create the Text widget and pack it to the righttext=Text(root)text.pack(side="right")# Insert 50 lines of text into the Text widgetforiinrange(50):text.insert("end",f"Line{i+1}\n")# Create the TkLineNumbers widget and pack it to the leftlinenums=TkLineNumbers(root,text,justify="center",colors=("#2197db","#ffffff"))linenums.pack(fill="y",side="left")# Redraw the line numbers when the text widget contents are modifiedtext.bind("<<Modified>>",lambdaevent:root.after_idle(linenums.redraw),add=True)# Start the mainloop for the root windowroot.mainloop()For a more complete example, seemisc/example.py.How to run and contributeRunningTo run the example, runpython3 misc/example.pyin the root directory. The project uses only standard library modules, so there are no dependencies. It will create a window with aTextwidget and aTkLineNumberswidget and 50 lines of text to mess around with.To test newer features or test code in a Pull Review, runpython3 tklinenums/tklinenums.pyin the root directory. Since the package is relatively small it doesn't have any relative imports, so you can run it directly.ContributingTo contribute, fork the repository, make your changes, and then make a pull request. If you want to add a feature, please open an issue first so we can discuss it.LicenseThis project is licensed under the MIT License - see theLICENSE.