Removed the importing of individual elements. Simplified and added more comments

This commit is contained in:
PySimpleGUI 2021-03-06 23:53:21 -05:00
parent 42a7f5999b
commit 55424278ba
1 changed files with 50 additions and 34 deletions

View File

@ -1,48 +1,64 @@
# this one long import has the effect of making the code more compact as there is no 'sg.' prefix required for Elements
import PySimpleGUI as sg
from PySimpleGUI import InputCombo, Combo, Multiline, ML, MLine, Checkbox, CB, Check, Button, B, Btn, ButtonMenu, Canvas, Column, Col, Combo, Frame, Graph, Image, InputText, Input, In, Listbox, LBox, Menu, Multiline, ML, MLine, OptionMenu, Output, Pane, ProgressBar, Radio, Slider, Spin, StatusBar, Tab, TabGroup, Table, Text, Txt, T, Tree, TreeData, VerticalSeparator, Window, Sizer
"""
Demo Columns and Frames
Demonstrates using mixture of Column and Frame elements to create a nice window layout.
Demo sg.Columns and sg.Frames
Demonstrates using mixture of sg.Column and sg.Frame elements to create a nice window layout.
A couple of the concepts shown here include:
* Using Columns and Frames with specific sizes on them
* Importing all required classes so that "sg." is not required on any objects. This makes the code more compact and readable
* Using sg.Columns and sg.Frames with specific sizes on them
* Buttons that have the same text on them that arew differentiated using explicit keys
* One way to hard-code the size of a Frame is to hard-code the size of a Column inside the frame
There are 3 columns. Two are side by side at the top and the third is along the bottom
CAUTION:
Using explicit sizes on Column and Frame elements may not have the same effect on
all computers. Hard coding parts of layouts can sometimes not have the same result on all computers.
There are 3 sg.Columns. Two are side by side at the top and the third is along the bottom
When there are multiple Columns on a row, be aware that the default is for those Columns to be
aligned along their center. If you want them to be top-aligned, then you need to use the
vtop helper function to make that happen.
Copyright 2021 PySimpleGUI
"""
sg.theme('GreenTan')
col2 = sg.Column([[sg.Frame('Accounts:', [[sg.Column([[sg.Listbox(['Account '+str(i) for i in range(1,16)],
key='-ACCT-LIST-',size=(15,20)),]],size=(150,400))]])]],pad=(0,0))
col2 = Column([[Frame('Accounts:', [[Column([[Listbox(['Account '+str(i) for i in range(1, 16)],
key='-ACCT-LIST-', size=(15, 20)), ]], size=(150, 400))]])]], pad=(0, 0))
col1 = sg.Column([
# Categories sg.Frame
[sg.Frame('Categories:',[[ sg.Radio('Websites', 'radio1', default=True, key='-WEBSITES-', size=(10,1)),
sg.Radio('Software', 'radio1', key='-SOFTWARE-', size=(10,1))]],)],
# Information sg.Frame
[sg.Frame('Information:', [[sg.Text(), sg.Column([[sg.Text('Account:')],
[sg.Input(key='-ACCOUNT-IN-', size=(19,1))],
[sg.Text('User Id:')],
[sg.Input(key='-USERID-IN-', size=(19,1)),
sg.Button('Copy', key='-USERID-')],
[sg.Text('Password:')],
[sg.Input(key='-PW-IN-', size=(19,1)),
sg.Button('Copy', key='-PASS-')],
[sg.Text('Location:')],
[sg.Input(key='-LOC-IN-', size=(19,1)),
sg.Button('Copy', key='-LOC-')],
[sg.Text('Notes:')],
[sg.Multiline(key='-NOTES-', size=(25,5))],
], size=(235,350), pad=(0,0))]])], ], pad=(0,0))
col1 = Column([
# Categories frame
[Frame('Categories:', [[ Radio('Websites', 'radio1', default=True, key='-WEBSITES-', size=(10, 1)),
Radio('Software', 'radio1', key='-SOFTWARE-', size=(10, 1))]],)],
# Information frame
[Frame('Information:', [[Text(), Column([[Text('Account:')],
[Input(key='-ACCOUNT-IN-', size=(19, 1))],
[Text('User Id:')],
[Input(key='-USERID-IN-', size=(19, 1)),
Button('Copy', key='-USERID-')],
[Text('Password:')],
[Input(key='-PW-IN-', size=(19, 1)),
Button('Copy', key='-PASS-')],
[Text('Location:')],
[Input(key='-LOC-IN-', size=(19, 1)),
Button('Copy', key='-LOC')],
[Text('Notes:')],
[Multiline(key='-NOTES-', size=(25, 5))],
], size=(235, 350), pad=(0, 0))]])], ], pad=(0, 0))
col3 = sg.Column([[sg.Frame('Actions:',
[[sg.Column([[sg.Button('Save'), sg.Button('Clear'), sg.Button('Delete'), ]],
size=(450,45), pad=(0,0))]])]], pad=(0,0))
col3 = Column([[Frame('Actions:', [[Column([[Button('Save'), Button(
'Clear'), Button('Delete'), ]], size=(450, 45), pad=(0, 0))]])]], pad=(0, 0))
# The final layout is a simple one
layout = [[col1, col2],
[col3]]
layout = [[col1, col2], [col3]]
# A perhaps better layout would have been to use the vtop layout helpful function.
# This would allow the col2 column to have a different height and still be top aligned
# layout = [sg.vtop([col1, col2]),
# [col3]]
window = Window('Passwords', layout)
window = sg.Window('Columns and Frames', layout)
while True:
event, values = window.read()