For a tkinter GUI, I must read in a Hex address in the form of '0x00' to set an I2C address. The way I am currently doing it is by reading the input as a string, converting the string to an integer, then converting that integer to an actual Hex value as shown in the partial code below:
GUI initialization:
self.I2CAddress=StringVar()
self.I2CAddress.set("0x00") #Sets Default value of '0x00'
Label(frame, text="Address: ").grid(row=5, column=4)
Entry(frame, textvariable=self.I2CAddress).grid(row=5, column=5)
Then inside the function:
addr = self.I2CAddress.get()
addrint = int(addr, 16)
addrhex = hex(addrint)
This works for most values, but my issue is that if I enter a small Hex value string such as '0x01', it converts to the proper integer of 1, but then that is converted to a Hex value of 0x1 instead of 0x01.
I am an EE and have very limited programming experience, so any help is greatly appreciated.