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
|
import Tkinter as gui
import tkColorChooser
class COLOR:
def __init__(self, value=0,label=''):
self.value = value
self.label = label
def set(self, value):
self.value = value
def get(self):
return self.value
def getLabel(self):
return self.label
def setColor(obj):
label = "Select %s"%obj.getLabel()
print label
color = tkColorChooser.askcolor(color="#%06x"%(obj.get()), title="Select %s"%label)
if color != (None, None):
color = int(color[1][1:], 16)
self.bitmap.setForeground(color)
self.refresh()
def appQuit(event=None):
win.quit()
win = gui.Tk()
bg = COLOR(0, label='Background')
fg = COLOR(0xfffff, label='Foreground')
gui.Button(win, text="Background color", command=lambda obj=bg:setColor(obj)).grid()
gui.Button(win, text="Foreground color", command=lambda obj=fg:setColor(obj)).grid()
win.bind("<Escape>", appQuit)
win.mainloop() |
Partager