-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkColourPicker.py
More file actions
34 lines (26 loc) · 1.02 KB
/
tkColourPicker.py
File metadata and controls
34 lines (26 loc) · 1.02 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
import tkinter as tk
import tkinter.colorchooser as colourChooser
class ColourPicker(tk.Frame):
def __init__(self, parent, width, height, command=None, key=None, index=0):
super().__init__(parent)
self.parent = parent
self.width = width
self.height = height
self.command = command
self.key = key
self.index = index
self.currentColour = "#FFFFFF"
self.clickable = tk.Button(self, width=self.width, height=self.height,
background=self.currentColour,
command=self.chooseColour)
self.clickable.pack()
def set(self, newColour):
self.currentColour = newColour
self.clickable.config(background=self.currentColour)
def get(self):
return self.currentColour
def chooseColour(self):
newColour = colourChooser.askcolor()
if newColour is not None:
self.set(newColour[1])
self.command(self.key, newColour[1], self.index)