Created
February 7, 2015 03:23
-
-
Save omz/ae96874dfbda54ed2771 to your computer and use it in GitHub Desktop.
Color picker.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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