Show colors in columns instead of rows

This commit is contained in:
MikeTheWatchGuy 2018-12-11 13:28:19 -05:00
parent db7b49f2c3
commit dfabb723a0
2 changed files with 38 additions and 13 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] >= 3: if sys.version_info[0] >= 3:
import PySimpleGUI as sg import PySimpleGUIQt as sg
else: else:
import PySimpleGUI27 as sg import PySimpleGUI27 as sg
@ -683,13 +683,19 @@ layout = [[sg.Text('Hover mouse to see RGB value, click for white & black text',
background_color='light green', background_color='light green',
pad=(0,(0,20))),]] pad=(0,(0,20))),]]
# -- Create primary color viewer window by building rows and appending to layout -- # -- Create primary color viewer window --
row = [] color_list = [key for key in color_map]
for i, color in enumerate(color_map): for rows in range(40):
row.append(sg.Button(color, button_color=('black', color), key=color, tooltip=color_map[color]))
if (i+1) % 15 == 0: # every 15 buttons make a new row
layout.append(row)
row = [] row = []
for i in range(12):
try:
color = color_list[rows+40*i]
row.append(sg.Button(color, button_color=('black', color), key=color))
except:
pass
layout.append(row)
window = sg.Window('Color Viewer', grab_anywhere=False, font=('any 9')).Layout(layout) window = sg.Window('Color Viewer', grab_anywhere=False, font=('any 9')).Layout(layout)

View File

@ -13,6 +13,9 @@ else:
Once large window is shown, you can click on any color and another window will popup Once large window is shown, you can click on any color and another window will popup
showing both white and black text on that color showing both white and black text on that color
""" """
COLORS = ['snow', 'ghost white', 'white smoke', 'gainsboro', 'floral white', 'old lace', COLORS = ['snow', 'ghost white', 'white smoke', 'gainsboro', 'floral white', 'old lace',
'linen', 'antique white', 'papaya whip', 'blanched almond', 'bisque', 'peach puff', 'linen', 'antique white', 'papaya whip', 'blanched almond', 'bisque', 'peach puff',
'navajo white', 'lemon chiffon', 'mint cream', 'azure', 'alice blue', 'lavender', 'navajo white', 'lemon chiffon', 'mint cream', 'azure', 'alice blue', 'lavender',
@ -90,16 +93,32 @@ COLORS = ['snow', 'ghost white', 'white smoke', 'gainsboro', 'floral white', 'ol
'grey84', 'grey85', 'grey86', 'grey87', 'grey88', 'grey89', 'grey90', 'grey91', 'grey92', 'grey84', 'grey85', 'grey86', 'grey87', 'grey88', 'grey89', 'grey90', 'grey91', 'grey92',
'grey93', 'grey94', 'grey95', 'grey97', 'grey98', 'grey99'] 'grey93', 'grey94', 'grey95', 'grey97', 'grey98', 'grey99']
sg.SetOptions(button_element_size=(12,1), element_padding=(0,0), auto_size_buttons=False, border_width=0) sg.SetOptions(button_element_size=(12,1), element_padding=(0,0), auto_size_buttons=False, border_width=0)
layout = [[sg.Text('Click on a color square to see both white and black text on that color', text_color='blue', font='Any 15')]] layout = [[sg.Text('Click on a color square to see both white and black text on that color', text_color='blue', font='Any 15')]]
row = [] row = []
layout = []
# -- Create primary color viewer window -- # -- Create primary color viewer window --
for i, color in enumerate(COLORS): for rows in range(40):
row.append(sg.Button(color, button_color=('black', color), key=color))
if (i+1) % 12 == 0:
layout.append(row)
row = [] row = []
for i in range(12):
try:
color = COLORS[rows+40*i]
row.append(sg.Button(color, button_color=('black', color), key=color))
except:
pass
layout.append(row)
# for i, color in enumerate(COLORS):
# row.append(sg.Button(color, button_color=('black', color), key=color))
# if (i+1) % 12 == 0:
# layout.append(row)
# row = []
window = sg.Window('Color Viewer', grab_anywhere=False, font=('any 9')).Layout(layout) window = sg.Window('Color Viewer', grab_anywhere=False, font=('any 9')).Layout(layout)