Skip to content

Instantly share code, notes, and snippets.

@omz
Created February 7, 2015 03:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omz/ae96874dfbda54ed2771 to your computer and use it in GitHub Desktop.
Save omz/ae96874dfbda54ed2771 to your computer and use it in GitHub Desktop.
Color picker.py
import ui
from random import randint
import console
import clipboard
# Generate some random hex colors:
colors = ['#%X%X%X' % (randint(0,255), randint(0,255), randint(0,255)) for i in xrange(25)]
def tapped(sender):
r, g, b, a = sender.background_color
hex_color = '#%X%X%X' % (int(r*255), int(g*255), int(b*255))
clipboard.set(hex_color)
console.hud_alert(hex_color + ' copied')
#Add buttons for all the colors to a scroll view:
scroll_view = ui.ScrollView(frame=(0, 0, 400, 400))
scroll_view.content_size = (0, len(colors) * 80)
for i, c in enumerate(colors):
swatch = ui.Button(frame=(0, i*80, 400, 80), background_color=c)
swatch.flex = 'w'
swatch.action = tapped
scroll_view.add_subview(swatch)
scroll_view.name = 'Random Color Picker'
scroll_view.present('sheet')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment