from Tkinter import *
def drawrgb():
r=sboxr.get()
g=sboxg.get()
b=sboxb.get()
rr=int(r, 10)
gg=int(g, 10)
bb=int(b, 10)
rgb=rr*256*256+gg*256+bb
srgb=hex(rgb)
srgb=srgb.replace('0x','')
srgb=srgb.zfill(6)
srgb='#' + srgb
print hex(rr),hex(gg), hex(bb),'-----',srgb
canvas1.create_rectangle(0, 0, 300, 100, fill=srgb)
if __name__ == "__main__":
root = Tk()
root.geometry('300x250+50+100')
labelr = Label(root,text='Red:').pack()
sboxr = Spinbox(root,from_=0, to=255,command=drawrgb)
sboxr.pack()
labelg = Label(root,text='Red:').pack()
sboxg = Spinbox(root,from_=0, to=255,command=drawrgb)
sboxg.pack()
labelb = Label(root,text='Red:').pack()
sboxb = Spinbox(root,from_=0, to=255,command=drawrgb)
sboxb.pack()
labelrgb = Label(root,text='Display').pack()
canvas1=Canvas(root, width=300,height=100)
canvas1.pack()
root.mainloop()
|