Merge pull request #3870 from PySimpleGUI/Dev-latest

Dev latest
This commit is contained in:
PySimpleGUI 2021-02-03 13:18:09 -05:00 committed by GitHub
commit 08823baf07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 6 deletions

View File

@ -671,14 +671,15 @@ color_map = {
def make_window():
layout = [[sg.Text(f'Swatches for {n} Colors', justification='center', font='Default 14')]]
layout = [[sg.Text(f'Swatches for {len(color_list)} Colors', font='Default 14'),],
[sg.Text(f'Hover - see color "name"\nRight click - see hex value\nClick - see buttons & hex value copied to clipboard', font='Default 12')]]
for rows in range(n//COLORS_PER_ROW+1):
for rows in range(len(color_list)//COLORS_PER_ROW+1):
row = []
for i in range(COLORS_PER_ROW):
try:
color = color_list[rows*COLORS_PER_ROW+i]
row.append(sg.T(sg.SYMBOL_SQUARE, text_color=color, background_color='black', pad=(0, 0), font=('Default', font_size), right_click_menu=['Nothing', color_map[color]],
row.append(sg.T(sg.SYMBOL_SQUARE, text_color=color, pad=(0, 0), font=('Default', font_size), right_click_menu=['Nothing', color_map[color]],
tooltip=color, enable_events=True, key=(color, color_map[color])))
except Exception as e:
pass
@ -687,6 +688,7 @@ def make_window():
return sg.Window('Color Swatches Viewer', layout, font='Any 9', element_padding=(0,0), border_depth=0)
def main():
sg.theme('black')
window = make_window()
# -- Event loop --
while True:
@ -704,10 +706,11 @@ def main():
window2 = sg.Window('Buttons with white and black text', layout2, keep_on_top=True, finalize=True)
window2.TKroot.clipboard_clear()
window2.TKroot.clipboard_append(color_hex)
window.close()
if __name__ == '__main__':
sg.popup_quick_message('Building your table... one moment please...', background_color='red', text_color='white', font='Any 14')
sg.popup_quick_message('Building your color window... one moment please...', background_color='red', text_color='white', font='Any 14')
sg.set_options(button_element_size=(12, 1),
element_padding=(0, 0),
@ -717,7 +720,6 @@ if __name__ == '__main__':
# -- Create primary color viewer window --
hex_to_color = {v: k for k, v in color_map.items()}
color_list = [key for key in color_map]
n = len(color_list)
COLORS_PER_ROW = 40
font_size = 18
main()
main()

View File

@ -0,0 +1,46 @@
"""
Multline Element - Input Justification
The justification of text for the Multiline element defaults to Left Justified
Because of the way tkinter's widget works, setting the justification when creating the element
is not enough to provide the correct justification.
The demo shows you the technique to achieve justified input
Key points:
* Enable events on the multiline
* Add 2 lines of code to your event loop
* If get mline element event
* Set the contents of the multline to be the correct justificaiton
Copyright 2021 PySimpleGUI
"""
import PySimpleGUI as sg
def main():
justification = 'l' # start left justified
layout = [[sg.Text('Multiline Element Input Justification')],
[sg.Multiline(size=(40,10), key='-MLINE-', justification=justification, enable_events=True, autoscroll=True)],
# We'll be fancy and allow user to choose which justification to use in the demo
[sg.Radio('Left', 0, True, k='-L-'), sg.Radio('Center', 0, k='-C-'),sg.Radio('Right', 0, k='-R-'),],
[sg.Button('Go'), sg.Button('Exit')]]
window = sg.Window('Window Title', layout, keep_on_top=True, resizable=True, finalize=True)
while True: # Event Loop
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Exit':
break
# Get desired justication from radio buttons. You don't need this if you know your justification already
justification = 'l' if values['-L-'] else 'r' if values['-R-'] else 'c'
# This is the important bit of code. It sets the current contents of the multiline to be the correct justification
if event == '-MLINE-':
window['-MLINE-'].update(values['-MLINE-'][:-1], justification=justification)
window.close()
if __name__ == '__main__':
main()