def table_example(): sg.SetOptions(auto_size_buttons=True) filename = sg.PopupGetFile('filename to open', no_window=True, file_types=(("CSV Files", "*.csv"),)) # --- populate table with file contents --- # if filename == '': sys.exit(69) data = [] header_list = [] button = sg.PopupYesNo('Does this file have column names already?') if filename is not None: try: df = pd.read_csv(filename, sep=',', engine='python', header=None) # Header=None means you directly pass the columns names to the dataframe data = df.values.tolist() # read everything else into a list of rows if button == 'Yes': # Press if you named your columns in the csv header_list = df.iloc[0].tolist() # Uses the first row (which should be column names) as columns names data = df[1:].values.tolist() # Drops the first row in the table (otherwise the header names and the first row will be the same) elif button == 'No': # Press if you didn't name the columns in the csv header_list = ['column' + str(x) for x in range(len(data[0]))] # Creates columns names for each column ('column0', 'column1', etc) except: sg.PopupError('Error reading file') sys.exit(69) # sg.SetOptions(element_padding=(0, 0)) col_layout = [[sg.Table(values=data, headings=header_list, display_row_numbers=True, auto_size_columns=False, size=(None, len(data)))]] canvas_size = (13*10*len(header_list), 600) # estimate canvas size - 13 pixels per char * 10 per column * num columns layout = [[sg.Column(col_layout, size=canvas_size, scrollable=True)]] window = sg.Window('Table', grab_anywhere=False) b, v = window.LayoutAndRead(layout) sys.exit(69)
def main(): # filename = 'C:/Python/MIDIVideo/PlainVideos/- 08-30 Ted Talk/TED Talk Short - Video+.mp4' filename = sg.PopupGetFile('Filename to play') if filename is None: exit(69) vidFile = cv.VideoCapture(filename) # ---===--- Get some Stats --- # num_frames = vidFile.get(cv.CAP_PROP_FRAME_COUNT) fps = vidFile.get(cv.CAP_PROP_FPS) sg.ChangeLookAndFeel('Dark') # define the window layout layout = [[ sg.Text('OpenCV Demo', size=(15, 1), pad=((510, 0), 3), justification='center', font='Helvetica 20') ], [sg.Image(filename='', key='image')], [ sg.Slider(range=(0, num_frames), size=(115, 10), orientation='h', key='slider') ], [ sg.ReadButton('Exit', size=(10, 2), pad=((600, 0), 3), font='Helvetica 14') ]] # create the window and show it without the plot window = sg.Window('Demo Application - OpenCV Integration', no_titlebar=False, location=(0, 0)) window.Layout(layout) window.ReadNonBlocking() # ---===--- LOOP through video file by frame --- # i = 0 temp_filename = next(tempfile._get_candidate_names()) + '.png' while vidFile.isOpened(): button, values = window.ReadNonBlocking() if button is 'Exit' or values is None: os.remove(temp_filename) exit(69) ret, frame = vidFile.read() if not ret: # if out of data stop looping break window.FindElement('slider').Update(i) i += 1 with open(temp_filename, 'wb') as f: Image.fromarray(frame).save(temp_filename, 'PNG') # save the PIL image as file window.FindElement('image').Update(filename=temp_filename)
def table_example(): filename = sg.PopupGetFile('filename to open', no_window=True, file_types=(("CSV Files", "*.csv"), )) # --- populate table with file contents --- # if filename == '': sys.exit(69) data = [] header_list = [] button = sg.PopupYesNo('Does this file have column names already?') if filename is not None: with open(filename, "r") as infile: reader = csv.reader(infile) if button == 'Yes': header_list = next(reader) try: data = list(reader) # read everything else into a list of rows if button == 'No': header_list = [ 'column' + str(x) for x in range(len(data[0])) ] except: sg.PopupError('Error reading file') sys.exit(69) sg.SetOptions(element_padding=(0, 0)) col_layout = [[ sg.Table(values=data, headings=header_list, max_col_width=25, auto_size_columns=True, justification='right', size=(None, len(data))) ]] canvas_size = ( 13 * 10 * len(header_list), 600 ) # estimate canvas size - 13 pixels per char * 10 char per column * num columns layout = [ [sg.Column(col_layout, size=canvas_size, scrollable=True)], ] window = sg.Window('Table', grab_anywhere=False).Layout(layout) b, v = window.Read() sys.exit(69)
def TestMenus(): import PySimpleGUI as sg sg.ChangeLookAndFeel('LightGreen') sg.SetOptions(element_padding=(0, 0)) # ------ Menu Definition ------ # menu_def = [ ['File', ['Open', 'Save', 'Properties']], [ 'Edit', ['Paste', [ 'Special', 'Normal', ], 'Undo'], ], ['Help', 'About...'], ] # ------ GUI Defintion ------ # layout = [[sg.Menu(menu_def, tearoff=True)], [sg.Output(size=(60, 20))], [sg.In('Test', key='input', do_not_clear=True)]] window = sg.Window("Windows-like program", default_element_size=(12, 1), auto_size_text=False, auto_size_buttons=False, default_button_element_size=(12, 1)).Layout(layout) # ------ Loop & Process button menu choices ------ # while True: button, values = window.Read() if button is None or button == 'Exit': return print('Button = ', button) # ------ Process menu choices ------ # if button == 'About...': sg.Popup('About this program', 'Version 1.0', 'PySimpleGUI rocks...') elif button == 'Open': filename = sg.PopupGetFile('file to open', no_window=True) print(filename) elif button == 'Properties': SecondForm()
def TableSimulation(): """ Display data in a table format """ sg.SetOptions(element_padding=(0, 0)) sg.PopupNoWait('Give it a few seconds to load please...', auto_close=True) menu_def = [ ['File', ['Open', 'Save', 'Exit']], [ 'Edit', ['Paste', [ 'Special', 'Normal', ], 'Undo'], ], ['Help', 'About...'], ] columm_layout = [[]] MAX_ROWS = 60 MAX_COL = 10 for i in range(MAX_ROWS): inputs = [sg.T('{}'.format(i), size=(4, 1), justification='right')] + [ sg.In(size=(10, 1), pad=(1, 1), justification='right', key=(i, j), do_not_clear=True) for j in range(MAX_COL) ] columm_layout.append(inputs) layout = [ [sg.Menu(menu_def)], [sg.T('Table Using Combos and Input Elements', font='Any 18')], [ sg. T('Type in a row, column and value. The form will update the values in realtime as you type' ), sg.In(key='inputrow', justification='right', size=(8, 1), pad=(1, 1), do_not_clear=True), sg.In(key='inputcol', size=(8, 1), pad=(1, 1), justification='right', do_not_clear=True), sg.In(key='value', size=(8, 1), pad=(1, 1), justification='right', do_not_clear=True) ], [sg.Column(columm_layout, size=(800, 600), scrollable=True)] ] window = sg.Window('Table', return_keyboard_events=True, grab_anywhere=False).Layout(layout) while True: button, values = window.Read() # --- Process buttons --- # if button is None or button == 'Exit': break elif button == 'About...': sg.Popup('Demo of table capabilities') elif button == 'Open': filename = sg.PopupGetFile('filename to open', no_window=True, file_types=(("CSV Files", "*.csv"), )) # --- populate table with file contents --- # if filename is not None: with open(filename, "r") as infile: reader = csv.reader(infile) try: data = list( reader) # read everything else into a list of rows except: sg.PopupError('Error reading file') continue # clear the table [ window.FindElement((i, j)).Update('') for j in range(MAX_COL) for i in range(MAX_ROWS) ] for i, row in enumerate(data): for j, item in enumerate(row): location = (i, j) try: # try the best we can at reading and filling the table target_element = window.FindElement(location) new_value = item if target_element is not None and new_value != '': target_element.Update(new_value) except: pass # if a valid table location entered, change that location's value try: location = (int(values['inputrow']), int(values['inputcol'])) target_element = window.FindElement(location) new_value = values['value'] if target_element is not None and new_value != '': target_element.Update(new_value) except: pass
#!/usr/bin/env python import sys if sys.version_info[0] < 3: import PySimpleGUI27 as sg else: import PySimpleGUI as sg # Here, have some windows on me.... [sg.PopupNoWait(location=(10 * x, 0)) for x in range(10)] print(sg.PopupYesNo('Yes No')) print(sg.PopupGetText('Get text', location=(1000, 200))) print(sg.PopupGetFile('Get file')) print(sg.PopupGetFolder('Get folder')) sg.Popup('Simple popup') sg.PopupNonBlocking('Non Blocking', location=(500, 500)) sg.PopupNoTitlebar('No titlebar') sg.PopupNoBorder('No border') sg.PopupNoFrame('No frame') # sg.PopupNoButtons('No Buttons') # don't mix with non-blocking... disaster ahead... sg.PopupCancel('Cancel') sg.PopupOKCancel('OK Cancel') sg.PopupAutoClose('Autoclose')
#!/usr/bin/env python import sys if sys.version_info[0] < 3: import PySimpleGUI27 as sg else: import PySimpleGUI as sg import csv filename = sg.PopupGetFile('filename to open', no_window=True, file_types=(("CSV Files", "*.csv"), )) # --- populate table with file contents --- # data = [] if filename is not None: with open(filename, "r") as infile: reader = csv.reader(infile) try: data = list(reader) # read everything else into a list of rows except: sg.PopupError('Error reading file') sys.exit(69) sg.SetOptions(element_padding=(0, 0)) col_layout = [[ sg.Table(values=data[1:][:], headings=[data[0][x] for x in range(len(data[0]))], max_col_width=25, auto_size_columns=True, display_row_numbers=True, justification='right',
def Everything(): sg.ChangeLookAndFeel('TanBlue') column1 = [[ sg.Text('Column 1', background_color=sg.DEFAULT_BACKGROUND_COLOR, justification='center', size=(10, 1)) ], [ sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1', key='spin1') ], [ sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2', key='spin2') ], [ sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3', key='spin3') ]] layout = [ [ sg.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25)) ], [sg.Text('Here is some text.... and a place to enter text')], [sg.InputText('This is my text', key='in1', do_not_clear=True)], [ sg.Checkbox('Checkbox', key='cb1'), sg.Checkbox('My second checkbox!', key='cb2', default=True) ], [ sg.Radio('My first Radio! ', "RADIO1", key='rad1', default=True), sg.Radio('My second Radio!', "RADIO1", key='rad2') ], [ sg.Multiline( default_text= 'This is the default Text should you decide not to type anything', size=(35, 3), key='multi1', do_not_clear=True), sg.Multiline(default_text='A second multi-line', size=(35, 3), key='multi2', do_not_clear=True) ], [ sg.InputCombo(('Combobox 1', 'Combobox 2'), key='combo', size=(20, 1)), sg.Slider(range=(1, 100), orientation='h', size=(34, 20), key='slide1', default_value=85) ], [ sg.InputOptionMenu( ('Menu Option 1', 'Menu Option 2', 'Menu Option 3'), key='optionmenu') ], [ sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3), key='listbox'), sg.Slider( range=(1, 100), orientation='v', size=(5, 20), default_value=25, key='slide2', ), sg.Slider( range=(1, 100), orientation='v', size=(5, 20), default_value=75, key='slide3', ), sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10, key='slide4'), sg.Column(column1, background_color='gray34') ], [sg.Text('_' * 80)], [sg.Text('Choose A Folder', size=(35, 1))], [ sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'), sg.InputText('Default Folder', key='folder', do_not_clear=True), sg.FolderBrowse() ], [ sg.ReadButton('Exit'), sg.Text(' ' * 40), sg.ReadButton('SaveSettings'), sg.ReadButton('LoadSettings') ] ] window = sg.Window('Form Fill Demonstration', default_element_size=(40, 1), grab_anywhere=False) # button, values = window.LayoutAndRead(layout, non_blocking=True) window.Layout(layout) while True: button, values = window.Read() if button is 'SaveSettings': filename = sg.PopupGetFile('Save Settings', save_as=True, no_window=True) window.SaveToDisk(filename) # save(values) elif button is 'LoadSettings': filename = sg.PopupGetFile('Load Settings', no_window=True) window.LoadFromDisk(filename) # load(form) elif button in ['Exit', None]: break
def PopupChooseFile(text_message): sg.ChangeLookAndFeel("Reddit") filename = sg.PopupGetFile(text_message) return filename
sg.MenuBar(menu_def), sg.Output(size=(60, 5), background_color='Black', text_color='Green', font='None') ]] window = sg.Window('LazyExtractor [Alpha]').Layout(layout) while True: event, value = window.Read() if event is None or event == 'Exit': break if event == 'NSP': filename = sg.PopupGetFile('Open File', no_window=True, file_types=(("Switch File Types", "*.nsp"), )) if filename is not '': print 'Extracting NSP:' window.Refresh() print subprocess.check_output([ 'squirrel', '-ogame_files/nca', '--NSP_copy_nca', '%s' % filename ]) window.Refresh() subprocess.check_output([ 'squirrel', '-ogame_files/nca', '--NSP_copy_ticket', '%s' % filename ]) subprocess.check_output([ 'squirrel', '-ogame_files/nca', '--NSP_copy_xml',