A simple Python Tkinter widget for displaying hexadecimal integers in a (ttk) spin box.
Project description
HexSpinbox
A simple Python Tkinter widget for displaying hexadecimal integers in a spin box.
Since the regular spinbox from tkinter does not support a hexadecimal format specifier (e.g. '%#x'),
I wrote a dedicated class for that.
It turned out to be surprisingly hard to get the built-in button functionality to work properly.
This implementation uses the values property to actually display hexadecimal numbers in the regular spinbox.
Installation
This has no dependencies other than tkinter/ttk, which are shipped with Python. You can download and install this widget via
pip install HexSpinbox
or simply copy the class from HexSpinbox.py to wherever you need it. It's less than a hundred lines.
Usage
Use it like any other ttk.Spinbox. Except for connecting to a variable.
Use only IntVars. To avoid confusion, I added an argument integer_var to use (instead of
textvariable.)
Also do not try to set a format. Only the default with small letters is implemented.
Lastly, be careful whith changing validation, which defaults to focusout.
Example:
import tkinter as tk
from HexSpinbox.HexSpinbox import HexSpinbox
root = tk.Tk()
var = tk.IntVar(value=2)
spinbox = HexSpinbox(root, from_=0, to=50, integer_var=var)
spinbox.pack()
root.mainloop()
Features
- shows an integer in hexadecimal form with prefix 0x and small letters.
- connection with Tk variables works
- uses spin buttons, up/down arrow key or mouse wheel to change value by 1
- allows typing a hexadecimal number (with or without 0x prefix and with small or capital letters)
- themes work
Here's what it looks like with the theme "breeze":
Known Issues
- After changing the value with something other than the spin buttons (e.g. typing in a value or changing the underlying IntVar by another widget) the up button will go down on the first button press
Implementation consideration
Q: Why not use a list of all possible values as strings for values, like that Stack-Overflow thread suggested?
A: Because that takes a lot of RAM. I use this spin box to select values from a 32bit integer range.
That gives 2^31+1 possibilities. Even using only a tenth of that as a list of strings took about 30GB on a test.
It is therefore simply not viable.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hexspinbox-0.1.0.tar.gz.
File metadata
- Download URL: hexspinbox-0.1.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad43ad1e0748716faa6aedb06438954ff39a815d2d86e2e6bdf2f4f04dd2dbf2
|
|
| MD5 |
ceffd8f077f80b66a582f8560abbfa6a
|
|
| BLAKE2b-256 |
b9f4bd9fac0d80eb3caa4235c4255f5eddc62db2465a344c973ad2830b260260
|
File details
Details for the file hexspinbox-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hexspinbox-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8012cd823ee2221fecda3fd83ebb3f4d6556b8af9bb92af4af08d55d474ccb0
|
|
| MD5 |
4916617ace0f47ef2abf58e76a56b3d6
|
|
| BLAKE2b-256 |
bb5f054b722749676c4539b00e6d2b00c5568647da5ddf694c35cba11a0fccad
|