[PYTHON] Make a Spinbox that can be displayed in HEX with Tkinter

Create a Spinbox that can be displayed in HEX with Python GUI Tkinter.

HEX.png

Spinbox does not support HEX even if you use the format option in Tkinter. However, it seems that internal addition is compatible with HEX. (increment = 1 is also valid for HEX) I wrote a sample program that explicitly shows the number of bytes as follows.

HexSpinbox.py


import tkinter as tk

class HexSpinbox(tk.Spinbox):
    def __init__(self, *args, **kwargs):
        self.var = tk.StringVar()
        self.bytenum = kwargs.pop('bytenum')
        max_val = 0x1<<(self.bytenum*8)
        super().__init__(*args, **kwargs, textvariable=self.var, from_=0,to=max_val,
                         increment=1, command=self.cange )

    def set(self, val):
        s = "0x{:0%dx}" % (self.bytenum*2)
        self.var.set(s.format(int(val)))
        
    def get(self):
        hstr = super().get()
        return int(hstr, 16)

    def cange(self):
        val = super().get()
        self.set(val)


if __name__ == "__main__":
    print("HexSpinbox")
    win = tk.Tk()
    hex = HexSpinbox(win, bytenum=2)
    hex.set(0xAA55)
    hex.pack()
    
    win.title("HexSpinbox test")
    win.mainloop()




Recommended Posts

Make a Spinbox that can be displayed in HEX with Tkinter
Make a Spinbox that can be displayed in Binary with Tkinter
Let's make a diagram that can be clicked with IPython
Make a currency chart that can be moved around with Plotly (2)
Make a currency chart that can be moved around with Plotly (1)
Color list that can be set with tkinter (memorial)
I made a familiar function that can be used in statistics with Python
A timer (ticker) that can be used in the field (can be used anywhere)
I made a shuffle that can be reset (reverted) with Python
How to make a rock-paper-scissors bot that can be easily moved (commentary)
Create a web app that can be easily visualized with Plotly Dash
[Can be done in 10 minutes] Create a local website quickly with Django
Draw a graph that can be moved around with HoloViews and Bokeh
A story that heroku that can be done in 5 minutes actually took 3 days
Get a list of camera parameters that can be set with cv2.VideoCapture and make it a dictionary type
Functions that can be used in for statements
Building Sphinx that can be written in Markdown
List packages that can be updated with pip
Iterative (recursive) processing with tkinter (displayed in order)
A memo for making a figure that can be posted to a journal with matplotlib
I want to create a priority queue that can be updated in Python (2.7)
If "can not be used when making a PIE object" appears in make
I registered PyQCheck, a library that can perform QuickCheck with Python, in PyPI.
Format DataFrame data with Pytorch into a form that can be trained with NN
Run the output code with tkinter, saying "A, pretending to be B" in python
Convert images from FlyCapture SDK to a form that can be used with openCV
Basic algorithms that can be used in competition pros
Make a simple Slackbot with interactive button in python
Python knowledge notes that can be used with AtCoder
ANTs image registration that can be used in 5 minutes
Create a flag in settings that will be True only when testing with Django
I tried to make a memo app that can be pomodoro, but a reflection record
Let's make a Mac app with Tkinter and py2app
The story that sendmail that can be executed in the terminal did not work with cron
A mechanism to call a Ruby method from Python that can be done in 200 lines
Limits that can be analyzed at once with MeCab
How to set up a simple SMTP server that can be tested locally in Python
Can be used with AtCoder! A collection of techniques for drawing short code in Python!
A memorandum (masOS) that import tkinter could not be done with python installed from pyenv
Format summary of formats that can be serialized with gensim
It seems that Skeleton Tracking can be done with RealSense
I made a simple typing game with tkinter in Python
Make a tky2jgd plugin with no practicality in QGIS Part 2
NumPy zeros can be defined even with a size of 0
Solution when the image cannot be displayed with tkinter [python]
Let's create a script that registers with Ideone.com in Python.
Create a life game that is manually updated with tkinter
Make a tky2jgd plugin with no practicality in QGIS Part 1
Goroutine (parallel control) that can be used in the field
Text analysis that can be done in 5 minutes [Word Cloud]
Goroutine that can be used in the field (errgroup.Group edition)
I made a puzzle game (like) with Tkinter in Python
Create a web API that can deliver images with Django
I tried to make a stopwatch using tkinter in python
Scripts that can be used when using bottle in Python
Implement a thread that can be paused by exploiting yield
I investigated the pretreatment that can be done with PyCaret
I made a plug-in that can "Daruma-san fell" with Minecraft
Evaluation index that can be specified in GridSearchCV of sklearn
Let's make dice with tkinter
Make a bookmarklet in Python