tklinenums


Nametklinenums JSON
Version 1.7.1 PyPI version JSON
download
home_pagehttps://github.com/Moosems/TkLineNums
SummaryA simple Tkinter widget for displaying line numbers
upload_time2023-09-05 20:05:22
maintainer
docs_urlNone
authorMoosems
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center">TkLineNums</h1>

> **Note**
> If 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 via `brew install python-tk` or with the distro package manager on Linux as documented [here](https://tecadmin.net/how-to-install-python-tkinter-on-linux/).

## Description
`TkLineNums` is a simple line numbering widget for Python's `tkinter` GUI library. It is directly connects to a `Text` widget and even supports ttk themes through the set_to_ttk_style method.

![img](misc/TkLineNumsPhoto.png)

## Features of the `TkLineNums` widget:

- 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 `-justify` option.
- Clicking and then dragging the mouse will scroll the text widget.
- Supports click dragging for selection.

# Installation

In the Command Line, paste the following: `pip install tklinenums`.

## Documentation
### `TkLineNums` Widget
|Options|Description|Type|
|---|---|---|
|master|The parent widget|Tkinter widget (defaults to `tkinter.Misc`)|
|textwidget|The `Text` widget the line numbers will connect to|Tkinter `Text` widget (or child class)|
|justify|The alignment of the line numbers|A string as either `"left"`, `"right"`, or `"center"`|
|colors|A way to provide coloring to the line numbers|A function, `(foreground, background)` tuple, or None. None (default) makes it use the `Text` widget'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.|
|*args|Arguments for the `Canvas` widget|Any arguments used for the `Canvas` widget|
|**kwargs|Keyword arguments for the `Canvas` widget|Any keyword arguments used for the `Canvas` widget|

### Basic Usage:
```python
from tkinter import Text, Tk
from tkinter.ttk import Style

from tklinenums import TkLineNumbers

# Create the root window
root = Tk()

# Create the Text widget and pack it to the right
text = Text(root)
text.pack(side="right")

# Insert 50 lines of text into the Text widget
for i in range(50):
    text.insert("end", f"Line {i+1}\n")

# Create the TkLineNumbers widget and pack it to the left
linenums = TkLineNumbers(root, text, justify="center", colors=("#2197db", "#ffffff"))
linenums.pack(fill="y", side="left")

# Redraw the line numbers when the text widget contents are modified
text.bind("<<Modified>>", lambda event: root.after_idle(linenums.redraw), add=True)

# Start the mainloop for the root window
root.mainloop()
```
For a more complete example, see [misc/example.py](./misc/example.py).

## How to run and contribute

### Running

To run the example, run `python3 misc/example.py` in the root directory. The project uses only standard library modules, so there are no dependencies. It will create a window with a `Text` widget and a `TkLineNumbers` widget and 50 lines of text to mess around with.

To test newer features or test code in a Pull Review, run `python3 tklinenums/tklinenums.py` in the root directory. Since the package is relatively small it doesn't have any relative imports, so you can run it directly.

### Contributing

To 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.


## License

This project is licensed under the MIT License - see the [LICENSE](./LISCENSE).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Moosems/TkLineNums",
    "name": "tklinenums",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Moosems",
    "author_email": "moosems.j@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c0/83/998b2b2225fa11c436792a4e228cc2acc19bc28fb0ff84aea0f3b3a70fea/tklinenums-1.7.1.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\">TkLineNums</h1>\n\n> **Note**\n> If 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 via `brew install python-tk` or with the distro package manager on Linux as documented [here](https://tecadmin.net/how-to-install-python-tkinter-on-linux/).\n\n## Description\n`TkLineNums` is a simple line numbering widget for Python's `tkinter` GUI library. It is directly connects to a `Text` widget and even supports ttk themes through the set_to_ttk_style method.\n\n![img](misc/TkLineNumsPhoto.png)\n\n## Features of the `TkLineNums` widget:\n\n- Clicking on line numbers will set the insert to the beginning of the line.\n- Shift clicking will select all text from the end of the line clicked by cursor and the insert position.\n- Scrolling the linebar will scroll the text widget (and vice versa).\n- Can handle elided lines (elided lines are lines that are not visible in the text widget).\n- Supports ttk themes and allows easy color customization.\n- Supports left, right, and center alignment with the `-justify` option.\n- Clicking and then dragging the mouse will scroll the text widget.\n- Supports click dragging for selection.\n\n# Installation\n\nIn the Command Line, paste the following: `pip install tklinenums`.\n\n## Documentation\n### `TkLineNums` Widget\n|Options|Description|Type|\n|---|---|---|\n|master|The parent widget|Tkinter widget (defaults to `tkinter.Misc`)|\n|textwidget|The `Text` widget the line numbers will connect to|Tkinter `Text` widget (or child class)|\n|justify|The alignment of the line numbers|A string as either `\"left\"`, `\"right\"`, or `\"center\"`|\n|colors|A way to provide coloring to the line numbers|A function, `(foreground, background)` tuple, or None. None (default) makes it use the `Text` widget'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.|\n|*args|Arguments for the `Canvas` widget|Any arguments used for the `Canvas` widget|\n|**kwargs|Keyword arguments for the `Canvas` widget|Any keyword arguments used for the `Canvas` widget|\n\n### Basic Usage:\n```python\nfrom tkinter import Text, Tk\nfrom tkinter.ttk import Style\n\nfrom tklinenums import TkLineNumbers\n\n# Create the root window\nroot = Tk()\n\n# Create the Text widget and pack it to the right\ntext = Text(root)\ntext.pack(side=\"right\")\n\n# Insert 50 lines of text into the Text widget\nfor i in range(50):\n    text.insert(\"end\", f\"Line {i+1}\\n\")\n\n# Create the TkLineNumbers widget and pack it to the left\nlinenums = TkLineNumbers(root, text, justify=\"center\", colors=(\"#2197db\", \"#ffffff\"))\nlinenums.pack(fill=\"y\", side=\"left\")\n\n# Redraw the line numbers when the text widget contents are modified\ntext.bind(\"<<Modified>>\", lambda event: root.after_idle(linenums.redraw), add=True)\n\n# Start the mainloop for the root window\nroot.mainloop()\n```\nFor a more complete example, see [misc/example.py](./misc/example.py).\n\n## How to run and contribute\n\n### Running\n\nTo run the example, run `python3 misc/example.py` in the root directory. The project uses only standard library modules, so there are no dependencies. It will create a window with a `Text` widget and a `TkLineNumbers` widget and 50 lines of text to mess around with.\n\nTo test newer features or test code in a Pull Review, run `python3 tklinenums/tklinenums.py` in the root directory. Since the package is relatively small it doesn't have any relative imports, so you can run it directly.\n\n### Contributing\n\nTo 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.\n\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](./LISCENSE).\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A simple Tkinter widget for displaying line numbers",
    "version": "1.7.1",
    "project_urls": {
        "Homepage": "https://github.com/Moosems/TkLineNums"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6c4c6eeff6222545ceafcc827b8aa480d86e55c93472ed13ab6f1e425aa168e0",
                "md5": "8a2f6620df1c5828c298317af49e8a93",
                "sha256": "66e45df7eac4630055a23ea34d13f36ab53191f5e03e03eb564ffd94e7298867"
            },
            "downloads": -1,
            "filename": "tklinenums-1.7.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8a2f6620df1c5828c298317af49e8a93",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6901,
            "upload_time": "2023-09-05T20:05:21",
            "upload_time_iso_8601": "2023-09-05T20:05:21.099784Z",
            "url": "https://files.pythonhosted.org/packages/6c/4c/6eeff6222545ceafcc827b8aa480d86e55c93472ed13ab6f1e425aa168e0/tklinenums-1.7.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c083998b2b2225fa11c436792a4e228cc2acc19bc28fb0ff84aea0f3b3a70fea",
                "md5": "435ad2c1d9d568afddf9d05c4df2e9c7",
                "sha256": "cbe870588c427cf61b301b0791562ff3e7159a037079ffd2727636e8e27c226b"
            },
            "downloads": -1,
            "filename": "tklinenums-1.7.1.tar.gz",
            "has_sig": false,
            "md5_digest": "435ad2c1d9d568afddf9d05c4df2e9c7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6641,
            "upload_time": "2023-09-05T20:05:22",
            "upload_time_iso_8601": "2023-09-05T20:05:22.801265Z",
            "url": "https://files.pythonhosted.org/packages/c0/83/998b2b2225fa11c436792a4e228cc2acc19bc28fb0ff84aea0f3b3a70fea/tklinenums-1.7.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-05 20:05:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Moosems",
    "github_project": "TkLineNums",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "tklinenums"
}
        
Elapsed time: 0.12227s