convert RGB values to hexadecimal.
from math import * from random import * from random import randint as RAND from kandinsky import * from kandinsky import fill_rect as FILL from ion import * from time import * r=0 g=0 b=0 print("**********************************") print("\nEnter a number between 0 - 255\n") try: r=int(input("\n\nRed: ")) except: r=0 try: g=int(input("\n\nGreen: ")) except: g=0 try: b=int(input("\n\nBlue: ")) except: b=0 r_hex=hex(r)[1:] g_hex=hex(g)[1:] b_hex=hex(b)[1:] sleep(0.15) FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) while not keydown(KEY_EXE): if r<=15: r_hex="0"+hex(r)[-1:] else: r_hex=hex(r)[-2:] if g<=15: g_hex="0"+hex(g)[-1:] else: g_hex=hex(g)[-2:] if b<=15: b_hex="0"+hex(b)[-1:] else: b_hex=hex(b)[-2:] draw_string("Red = "+str(r)+", Hex: "+str(r_hex),5,70,(255,0,0),(255,)*3) draw_string("Green = "+str(g)+", Hex: "+str(g_hex),5,90,(0,100,0),(255,)*3) draw_string("Blue = "+str(b)+", Hex: "+str(b_hex),5,110,(0,0,255),(255,)*3) if keydown(KEY_LEFTPARENTHESIS): sleep(0.2) FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) r-=1 if keydown(KEY_SHIFT): sleep(0.1) r-=5 if keydown(KEY_RIGHTPARENTHESIS): sleep(0.2) FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) r+=1 if keydown(KEY_SHIFT): sleep(0.1) r+=5 if keydown(KEY_MULTIPLICATION): sleep(0.2) FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) g-=1 if keydown(KEY_SHIFT): sleep(0.1) g-=5 if keydown(KEY_DIVISION): sleep(0.2) FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) g+=1 if keydown(KEY_SHIFT): sleep(0.1) g+=5 if keydown(KEY_PLUS): sleep(0.2) FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) b-=1 if keydown(KEY_SHIFT): sleep(0.1) b-=5 if keydown(KEY_MINUS): sleep(0.2) FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) b+=1 if keydown(KEY_SHIFT): sleep(0.1) b+=5 if keydown(KEY_BACKSPACE): sleep(0.2) r=255 FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) if keydown(KEY_TOOLBOX): sleep(0.2) r=0 FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) if keydown(KEY_COMMA): sleep(0.2) g=0 FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) if keydown(KEY_POWER): sleep(0.2) g=255 FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) if keydown(KEY_SQRT): sleep(0.2) b=0 FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) if keydown(KEY_SQUARE): sleep(0.2) b=255 FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) if keydown(KEY_OK): sleep(0.2) r=RAND(0,255) g=RAND(0,255) b=RAND(0,255) FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) if r<0: r=0 if r>255: r=255 if g<0: g=0 if g>255: g=255 if b<0: b=0 if b>255: b=255 if keydown(KEY_NINE): sleep(0.15) try: r=int(input("\n\nRed: ")) except: r=0 sleep(0.2) FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) if keydown(KEY_SIX): sleep(0.15) try: g=int(input("\n\nGreen: ")) except: g=0 sleep(0.2) FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,60,320,80,(255,)*3) if keydown(KEY_THREE): sleep(0.15) try: b=int(input("\n\nBlue: ")) except: b=0 sleep(0.2) FILL(0,0,320,220,(r,g,b)) FILL(0,50,320,100,(0,0,0)) FILL(0,47,320,3,(0,0,250)) FILL(0,150,320,3,(0,0,250)) FILL(0,60,320,80,(255,)*3) draw_string("(R,G,B) = ("+str(r)+","+str(g)+","+str(b)+")",5,170,(255,)*3,(0,0,0)) draw_string('HEX: '+'"#'+str(r_hex)+str(g_hex)+str(b_hex)+'"',140,200,(0,0,0),(255,255,0)) draw_string("Use keys: ( ) * / + - 9 6 3",1,1,"#00ff00","#000000") draw_string("[SHIFT] = Faster",2,25,(255,255,0),(0,0,255)) draw_string("[EXE] = Print",175,25,(255,)*3,(250,0,0)) FILL(0,47,320,3,(155,)*3) FILL(0,150,320,3,(155,)*3) FILL(260,75,50,50,(r,g,b)) FILL(260,75,4,50,(85,)*3) FILL(260+50-2,75,2,50,(85,)*3) FILL(260,75+50-1,50,1,(85,)*3) FILL(0,0,320,220,(200,255,255)) draw_string("Press [OK]",100,90) print("\n************************") print("\nrgb: ",(r,g,b)) hex_code=('"#',r_hex,g_hex,b_hex,'"') new_hex_code="" for i in range(len(hex_code)): if hex_code[i] != " ": new_hex_code += hex_code[i] print("\nHEX:",new_hex_code) print("\n************************")