confused
confused

Reputation: 1323

Convert number to tkinter color

Is there a simple way to convert a number into a tkinter color (#ffeedd).

I'm already setup to take the number and multiply it by 8 to give me a bit more color range leeway, and maybe even multiply it by 16 depending on just how much leeway I have to work with, not sure on how much leeway I will have yet... but I'm guessing I'll only be able to multiply by 8. How do I take that number and convert it over so I can use it with canvas.create_line((x,y), (x,y), fill = 'color'). I tried hex(number) but it just gives me back that color 0x0 doesn't exists... kinda figured that would happen but thought it would be worth a try.

a = 326
b = a * 8
canvas.create_line((x,y), (x,y), fill = b)

Upvotes: 5

Views: 876

Answers (1)

patthoyts
patthoyts

Reputation: 33203

Ensure you have 3 or 6 hex digits. For instance:

frame.configure(background="#{0:06X}".format(0x808080))

The actual permitted set of color specfications is given in the GetColor manual page.

Upvotes: 6

Related Questions