Major update of all demo programs to use new PEP8 bindings, etc

This commit is contained in:
PySimpleGUI 2019-10-23 16:10:03 -04:00
parent 3f7c87c562
commit 7f52778bcc
307 changed files with 19546 additions and 3297 deletions

View file

@ -1,9 +1,4 @@
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
# import PySimpleGUIWeb as sg # take your pick of ports. Runs on both
else:
import PySimpleGUI27 as sg
import PySimpleGUI as sg
import random
import string
@ -17,38 +12,41 @@ import string
BOX_SIZE = 25
layout = [
[sg.Text('Crossword Puzzle Using PySimpleGUI'), sg.Text('', key='_OUTPUT_')],
[sg.Graph((800,800), (0,450), (450,0), key='_GRAPH_', change_submits=True, drag_submits=False)],
[sg.Button('Show'), sg.Button('Exit')]
]
[sg.Text('Crossword Puzzle Using PySimpleGUI'), sg.Text('', key='-OUTPUT-')],
[sg.Graph((800, 800), (0, 450), (450, 0), key='-GRAPH-',
change_submits=True, drag_submits=False)],
[sg.Button('Show'), sg.Button('Exit')]
]
window = sg.Window('Window Title', ).Layout(layout).Finalize()
window = sg.Window('Window Title', layout, finalize=True)
g = window.FindElement('_GRAPH_')
g = window['-GRAPH-']
for row in range(16):
for col in range(16):
if random.randint(0,100) > 10:
g.DrawRectangle((col * BOX_SIZE + 5, row * BOX_SIZE + 3), (col * BOX_SIZE + BOX_SIZE + 5, row * BOX_SIZE + BOX_SIZE + 3), line_color='black')
if random.randint(0, 100) > 10:
g.draw_rectangle((col * BOX_SIZE + 5, row * BOX_SIZE + 3), (col * BOX_SIZE + BOX_SIZE + 5, row * BOX_SIZE + BOX_SIZE + 3), line_color='black')
else:
g.DrawRectangle((col * BOX_SIZE + 5, row * BOX_SIZE + 3), (col * BOX_SIZE + BOX_SIZE + 5, row * BOX_SIZE + BOX_SIZE + 3), line_color='black', fill_color='black')
g.draw_rectangle((col * BOX_SIZE + 5, row * BOX_SIZE + 3), (col * BOX_SIZE + BOX_SIZE + 5, row * BOX_SIZE + BOX_SIZE + 3), line_color='black', fill_color='black')
g.DrawText('{}'.format(row * 6 + col + 1), (col * BOX_SIZE + 10, row * BOX_SIZE + 8))
g.draw_text('{}'.format(row * 6 + col + 1),
(col * BOX_SIZE + 10, row * BOX_SIZE + 8))
while True: # Event Loop
event, values = window.Read()
event, values = window.read()
print(event, values)
if event is None or event == 'Exit':
if event in (None, 'Exit'):
break
mouse = values['_GRAPH_']
mouse = values['-GRAPH-']
if event == '_GRAPH_':
if event == '-GRAPH-':
if mouse == (None, None):
continue
box_x = mouse[0]//BOX_SIZE
box_y = mouse[1]//BOX_SIZE
letter_location = (box_x * BOX_SIZE + 18, box_y * BOX_SIZE + 17)
print(box_x, box_y)
g.DrawText('{}'.format(random.choice(string.ascii_uppercase)), letter_location, font='Courier 25')
g.draw_text('{}'.format(random.choice(string.ascii_uppercase)),
letter_location, font='Courier 25')
window.Close()
window.close()