Fixed up indentation problems... merged back from Jason

This commit is contained in:
PySimpleGUI 2021-01-30 14:42:09 -05:00
parent d42a0ccfc4
commit 108d5308dc
1 changed files with 130 additions and 130 deletions

View File

@ -2761,11 +2761,11 @@ layout = [ [sg.Text('Text area', key='_TEXT_')],
window = sg.Window('Window Title', layout) window = sg.Window('Window Title', layout)
while True: # Event Loop while True: # Event Loop
event, values = window.read() event, values = window.read()
print(event, values) print(event, values)
if event == sg.WIN_CLOSED or event == 'Exit': if event == sg.WIN_CLOSED or event == 'Exit':
break break
if event == 'Chrome': if event == 'Chrome':
sp = subprocess.Popen([CHROME, values['_URL_']], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) sp = subprocess.Popen([CHROME, values['_URL_']], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
window.close() window.close()
@ -2919,7 +2919,7 @@ while True:
break break
``` ```
## One Element Updating Another - Compound Elements ## One Element Updating Another - Compound Elements
![image](https://user-images.githubusercontent.com/13696193/49649095-1be40700-f9f6-11e8-981e-f56eb8404ae7.png) ![image](https://user-images.githubusercontent.com/13696193/49649095-1be40700-f9f6-11e8-981e-f56eb8404ae7.png)
@ -2937,11 +2937,11 @@ layout = [[sg.Text('Slider Demonstration'), sg.Text('', key='_OUTPUT_')],
window = sg.Window('Window Title', layout) window = sg.Window('Window Title', layout)
while True: # Event Loop while True: # Event Loop
event, values = window.read() event, values = window.read()
print(event, values) print(event, values)
if event == sg.WIN_CLOSED or event == 'Exit': if event == sg.WIN_CLOSED or event == 'Exit':
break break
window['_LEFT_'].update(values['_SLIDER_']) window['_LEFT_'].update(values['_SLIDER_'])
window['_RIGHT_'].update(values['_SLIDER_']) window['_RIGHT_'].update(values['_SLIDER_'])
window.close() window.close()
@ -2980,9 +2980,9 @@ while True:
if ev1 == 'Launch 2' and not win2_active: if ev1 == 'Launch 2' and not win2_active:
win2_active = True win2_active = True
win1.Hide() win1.Hide()
layout2 = [[sg.Text('Window 2')], # note must create a layout from scratch every time. No reuse layout2 = [[sg.Text('Window 2')], # note must create a layout from scratch every time. No reuse
[sg.Button('Exit')]] [sg.Button('Exit')]]
win2 = sg.Window('Window 2', layout2) win2 = sg.Window('Window 2', layout2)
while True: while True:
@ -2990,7 +2990,7 @@ while True:
if ev2 == sg.WIN_CLOSED or ev2 == 'Exit': if ev2 == sg.WIN_CLOSED or ev2 == 'Exit':
win2.Close() win2.Close()
win2_active = False win2_active = False
win1.UnHide() win1.UnHide()
break break
``` ```
@ -3317,65 +3317,65 @@ Use the upper half to generate your hash code. Then paste it into the code in t
![password hash](https://user-images.githubusercontent.com/13696193/45129441-ab58f000-b151-11e8-8a46-c2789bb7824e.jpg) ![password hash](https://user-images.githubusercontent.com/13696193/45129441-ab58f000-b151-11e8-8a46-c2789bb7824e.jpg)
```python ```python
import PySimpleGUI as sg import PySimpleGUI as sg
import hashlib import hashlib
''' '''
Create a secure login for your scripts without having to include your password in the program. Create an SHA1 hash code for your password using the GUI. Paste into variable in final program Create a secure login for your scripts without having to include your password in the program. Create an SHA1 hash code for your password using the GUI. Paste into variable in final program
1. Choose a password 1. Choose a password
2. Generate a hash code for your chosen password by running program and entering 'gui' as the password 2. Generate a hash code for your chosen password by running program and entering 'gui' as the password
3. Type password into the GUI 3. Type password into the GUI
4. Copy and paste hash code Window GUI into variable named login_password_hash 4. Copy and paste hash code Window GUI into variable named login_password_hash
5. Run program again and test your login! 5. Run program again and test your login!
''' '''
# Use this GUI to get your password's hash code # Use this GUI to get your password's hash code
def HashGeneratorGUI(): def HashGeneratorGUI():
layout = [[sg.T('Password Hash Generator', size=(30,1), font='Any 15')], layout = [[sg.T('Password Hash Generator', size=(30,1), font='Any 15')],
[sg.T('Password'), sg.In(key='password')], [sg.T('Password'), sg.In(key='password')],
[sg.T('SHA Hash'), sg.In('', size=(40,1), key='hash')], [sg.T('SHA Hash'), sg.In('', size=(40,1), key='hash')],
] ]
window = sg.Window('SHA Generator', layout, auto_size_text=False, default_element_size=(10,1), window = sg.Window('SHA Generator', layout, auto_size_text=False, default_element_size=(10,1),
text_justification='r', return_keyboard_events=True, grab_anywhere=False) text_justification='r', return_keyboard_events=True, grab_anywhere=False)
while True: while True:
event, values = window.read() event, values = window.read()
if event == sg.WIN_CLOSED: if event == sg.WIN_CLOSED:
exit(69) exit(69)
password = values['password'] password = values['password']
try: try:
password_utf = password.encode('utf-8') password_utf = password.encode('utf-8')
sha1hash = hashlib.sha1() sha1hash = hashlib.sha1()
sha1hash.update(password_utf) sha1hash.update(password_utf)
password_hash = sha1hash.hexdigest() password_hash = sha1hash.hexdigest()
window['hash'].update(password_hash) window['hash'].update(password_hash)
except: except:
pass pass
# ----------------------------- Paste this code into your program / script ----------------------------- # ----------------------------- Paste this code into your program / script -----------------------------
# determine if a password matches the secret password by comparing SHA1 hash codes # determine if a password matches the secret password by comparing SHA1 hash codes
def PasswordMatches(password, hash): def PasswordMatches(password, hash):
password_utf = password.encode('utf-8') password_utf = password.encode('utf-8')
sha1hash = hashlib.sha1() sha1hash = hashlib.sha1()
sha1hash.update(password_utf) sha1hash.update(password_utf)
password_hash = sha1hash.hexdigest() password_hash = sha1hash.hexdigest()
if password_hash == hash: if password_hash == hash:
return True return True
else:
return False
login_password_hash = '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'
password = sg.popup_get_text('Password', password_char='*')
if password == 'gui': # Remove when pasting into your program
HashGeneratorGUI() # Remove when pasting into your program
exit(69) # Remove when pasting into your program
if PasswordMatches(password, login_password_hash):
print('Login SUCCESSFUL')
else: else:
print('Login FAILED!!') return False
login_password_hash = '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'
password = sg.popup_get_text('Password', password_char='*')
if password == 'gui': # Remove when pasting into your program
HashGeneratorGUI() # Remove when pasting into your program
exit(69) # Remove when pasting into your program
if PasswordMatches(password, login_password_hash):
print('Login SUCCESSFUL')
else:
print('Login FAILED!!')
``` ```
## Desktop Floating Toolbar ## Desktop Floating Toolbar