import tkinter.messagebox
import tkinter.colorchooser
win = tkinter.Tk()
win.title('tkinter:颜色选取对话框')
win.geometry('320x480')
color_dialog = tkinter.colorchooser.Chooser(win)
def colordialog():
color = color_dialog.show()
# color对象得到的赋值是一个元组,格式:((R, G, B), "#rrggbb")
# 例:当选择红色确认后返回值为(255.99609375, 0.0, 0.0), '#ff0000')
tkinter.messagebox.showinfo(title='提示',
message=
'''
所选颜色
1. 十六进制颜色码是: %s
2. RGB数值为: %s
'''
% (color[1], color[0]))
tkinter.Button(win,
text='打开选色对话框',
command=colordialog).pack()
win.mainloop()