-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcolour.py
More file actions
68 lines (58 loc) · 2.34 KB
/
colour.py
File metadata and controls
68 lines (58 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# colour.py
# A simple Tkinter GUI to test the blinkM on the Raspberry Pi.
#
# Based on: clrpick.py from
# http://infohost.nmt.edu/tcc/help/pubs/tkinter//dialogs.html#tkColorChooser
from tkinter import *
from tkinter import ttk
from tkinter.colorchooser import *
#from demopanels import MsgPanel, SeeDismissPanel
from blinkm import blinkm
class ColorPickDemo(ttk.Frame):
def __init__(self, isapp=True, name='clrpickdemo'):
ttk.Frame.__init__(self, name=name)
self.pack(expand=Y, fill=BOTH)
self.master.title('BlinkM Color Picker Demo')
self.isapp = isapp
self._create_widgets()
self.bm = blinkm(0x09)
self.bm.goToRGB((0,0,0))
self.bm.setFadeSpeed(4)
self.prev_color = (0,0,0)
def _create_widgets(self):
self.lblColor = Label(self,text="Color")
self.lblColor.pack(side=TOP)
self._create_demo_panel()
def _create_demo_panel(self):
demoPanel = ttk.Frame(self, name='demo')
demoPanel.pack(side=TOP, fill=BOTH, expand=Y)
bgBtn = ttk.Button(demoPanel, text='Go to Colour',
width=25, name='bgBtn',
command=lambda: self._set_color('goto'))
fgBtn = ttk.Button(demoPanel, text='Fade to Colour',
width=25, name='fgBtn',
command=lambda: self._set_color('fade'))
bgBtn.pack(side=TOP, anchor=CENTER, pady='2m')
fgBtn.pack(side=TOP, anchor=CENTER, pady='2m')
def _set_color(self, opt):
# askcolor() returns a tuple of the form
# ((r,g,b), hex) or (None, None) if cancelled
color = askcolor(parent=self,
title='Choose a {} color'.format(opt),
initialcolor=self.prev_color)
if color[0]:
hex_colour = color[1]
r,g,b = color[0]
r = int(r)
g = int(g)
b = int(b)
self.prev_color = color = (r,g,b)
if opt == "goto":
print("Goto Colour {}".format(color))
self.bm.goToRGB(color)
elif opt == "fade":
print("Fade Colour {}".format(color))
self.bm.fadeToRGB(color)
self.lblColor['bg'] = hex_colour
if __name__ == '__main__':
ColorPickDemo().mainloop()