当前位置: 首页>>代码示例>>Python>>正文


Python PySimpleGUI.Input方法代码示例

本文整理汇总了Python中PySimpleGUI.Input方法的典型用法代码示例。如果您正苦于以下问题:Python PySimpleGUI.Input方法的具体用法?Python PySimpleGUI.Input怎么用?Python PySimpleGUI.Input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PySimpleGUI的用法示例。


在下文中一共展示了PySimpleGUI.Input方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_settings_window

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def create_settings_window(settings):
    sg.theme(settings['theme'])

    def TextLabel(text): return sg.Text(text+':', justification='r', size=(15,1))

    layout = [  [sg.Text('Settings', font='Any 15')],
                [TextLabel('Max Users'), sg.Input(key='-MAX USERS-')],
                [TextLabel('User Folder'),sg.Input(key='-USER FOLDER-'), sg.FolderBrowse(target='-USER FOLDER-')],
                [TextLabel('Zipcode'),sg.Input(key='-ZIPCODE-')],
                [TextLabel('Theme'),sg.Combo(sg.theme_list(), size=(20, 20), key='-THEME-')],
                [sg.Button('Save'), sg.Button('Exit')]  ]

    window = sg.Window('Settings', layout, keep_on_top=True, finalize=True)

    for key in SETTINGS_KEYS_TO_ELEMENT_KEYS:   # update window with the values read from settings file
        try:
            window[SETTINGS_KEYS_TO_ELEMENT_KEYS[key]].update(value=settings[key])
        except Exception as e:
            print(f'Problem updating PySimpleGUI window from settings. Key = {key}')

    return window

########################################## Main Program Window & Event Loop ########################################## 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:25,代码来源:Demo_Settings_Save_Load.py

示例2: main

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def main():
    layout = [  [sg.Text('Enter the command you wish to run')],
                [sg.Input(key='_IN_')],
                [sg.Output(size=(60,15))],
                [sg.Button('Run'), sg.Button('Exit')] ]

    window = sg.Window('Realtime Shell Command Output', layout)

    while True:             # Event Loop
        event, values = window.Read()
        # print(event, values)
        if event in (None, 'Exit'):
            break
        elif event == 'Run':
            runCommand(cmd=values['_IN_'], window=window)
    window.Close() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:18,代码来源:Demo_Script_Launcher_Realtime_Output.py

示例3: main

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def main():
    layout = [
        [sg.Multiline(size=(110, 30), font='courier 10', background_color='black', text_color='white', key='-MLINE-')],
        [sg.T('Promt> '), sg.Input(key='-IN-', focus=True, do_not_clear=False)],
        [sg.Button('Run', bind_return_key=True), sg.Button('Exit')]]

    window = sg.Window('Realtime Shell Command Output', layout)

    while True:  # Event Loop
        event, values = window.read()
        # print(event, values)
        if event in (sg.WIN_CLOSED, 'Exit'):
            break
        elif event == 'Run':
            runCommand(cmd=values['-IN-'], window=window)
    window.close() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:18,代码来源:Demo_Script_Launcher_ANSI_Color_Output.py

示例4: main

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def main():
	layout = [
				[sg.Output(size=(110,30), background_color='black', text_color='white')],
				[sg.T('Promt> '), sg.Input(key='-IN-', do_not_clear=False)],
				[sg.Button('Run', bind_return_key=True), sg.Button('Exit')] ]

	window = sg.Window('Realtime Shell Command Output', layout)

	while True:             # Event Loop
		event, values = window.read()
		# print(event, values)
		if event in (sg.WIN_CLOSED, 'Exit'):
			break
		elif event == 'Run':
			runCommand(cmd=values['-IN-'], window=window)
	window.close() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:18,代码来源:Demo_Script_Launcher_Realtime_Output.py

示例5: InfoIn

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def InfoIn(text, key):
    return [sg.Text(text, size=(8, 1), justification='r', font='Any 14'), sg.Input(key=key)] 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:4,代码来源:YouTube_2020_Lesson - Source File 1.py

示例6: __init__

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def __init__(self):
        layout = [[sg.Text('Enter Text')],
                  [sg.Input(size=(17, 1), key='input1', do_not_clear=True)],
                  [sg.InputText(size=(17, 1), key='input2', do_not_clear=True)],
                  [sg.Button('on-screen keyboard', key='keyboard')],
                  [sg.Button('close', key='close')]]

        self.mainWindow = sg.Window('On-screen test',
                                    grab_anywhere=True,
                                    no_titlebar=False,
                                    ).Layout(layout).Finalize()
        location = self.mainWindow.CurrentLocation()
        location = location[0]-200, location[1]+200
        self.keyboard = keyboard(location)
        self.focus = None 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:17,代码来源:Demo_Touch_Keyboard.py

示例7: main

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def main():
    sg.theme('Dark Blue 3')
    layout = [[sg.Text('Send an Email', font='Default 18')],
              [sg.T('From:', size=(8,1)), sg.Input(key='-EMAIL FROM-', size=(35,1))],
              [sg.T('To:', size=(8,1)), sg.Input(key='-EMAIL TO-', size=(35,1))],
              [sg.T('Subject:', size=(8,1)), sg.Input(key='-EMAIL SUBJECT-', size=(35,1))],
              [sg.T('Mail login information', font='Default 18')],
              [sg.T('User:', size=(8,1)), sg.Input(key='-USER-', size=(35,1))],
              [sg.T('Password:', size=(8,1)), sg.Input(password_char='*', key='-PASSWORD-', size=(35,1))],
              [sg.Multiline('Type your message here', size=(60,10), key='-EMAIL TEXT-')],
              [sg.Button('Send'), sg.Button('Exit')]]

    window = sg.Window('Send An Email', layout)

    while True:  # Event Loop
        event, values = window.read()
        if event in (sg.WIN_CLOSED, 'Exit'):
            break
        if event == 'Send':
            if sg.__name__ != 'PySimpleGUIWeb':     # auto close popups not yet supported in PySimpleGUIWeb
                sg.popup_quick_message('Sending your message... this will take a moment...', background_color='red')
            send_an_email(from_address=values['-EMAIL FROM-'],
                          to_address=values['-EMAIL TO-'],
                          subject=values['-EMAIL SUBJECT-'],
                          message_text=values['-EMAIL TEXT-'],
                          user=values['-USER-'],
                          password=values['-PASSWORD-'])

    window.close() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:31,代码来源:Demo_Email_Send.py

示例8: layout4

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def layout4():
    layout = [[sg.Text('Enter some info')] + [sg.Input()] + [sg.Exit()]]

    window = sg.Window('Generated Layouts', layout)

    event, values = window.read()

    print(event, values)
    window.close() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:11,代码来源:Demo_Layout_Generation.py

示例9: ValidateInput

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def ValidateInput(values, window):
    '''Returns tuple (success, extraction_type)'''
    global indx

    i_path = values[0] # input file/folder
    o_path = values[1] # output folder
    ext_type = ''

    if len(i_path) == 0:
        sg.PopupError('No INPUT file or folder selected!')
        return False, ext_type
    elif not os.path.exists(i_path):
        sg.PopupError('INPUT file/folder does not exist!')
        return False, ext_type
    elif os.path.isdir(i_path):
        ext_type = 'fs'
    else: # must be an existing file then
        if not i_path.lower().endswith('.tar') and not i_path.lower().endswith('.zip'):
            sg.PopupError('Input file is not a supported archive! ', i_path)
            return False, ext_type
        else:
            ext_type = Path(i_path).suffix[1:].lower() 
    
    # check output now
    if len(o_path) == 0 : # output folder
        sg.PopupError('No OUTPUT folder selected!')
        return False, ext_type

    one_element_is_selected = False
    for x in range(1000, indx):
        if window.FindElement(x).Get():
            one_element_is_selected = True
            break
    if not one_element_is_selected:
        sg.PopupError('No module selected for processing!')
        return False, ext_type

    return True, ext_type

# initialize CheckBox control with module name 
开发者ID:abrignoni,项目名称:iLEAPP,代码行数:42,代码来源:ileappGUI.py

示例10: the_gui

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def the_gui():
    """
    Starts and executes the GUI
    Reads data from a global variable and displays
    Returns when the user exits / closes the window
    """
    global message, progress

    sg.theme('Light Brown 3')

    layout = [[sg.Text('Long task to perform example')],
              [sg.Output(size=(80, 12))],
              [sg.Text('Number of seconds your task will take'),
               sg.Input(key='-SECONDS-', size=(5, 1)),
               sg.Button('Do Long Task', bind_return_key=True),
               sg.CBox('ONE chunk, cannot break apart', key='-ONE CHUNK-')],
              [sg.Text('Work progress'), sg.ProgressBar(total, size=(20, 20), orientation='h', key='-PROG-')],
              [sg.Button('Click Me'), sg.Button('Exit')], ]

    window = sg.Window('Multithreaded Demonstration Window', layout)

    thread = None

    # --------------------- EVENT LOOP ---------------------
    while True:
        event, values = window.read(timeout=100)
        if event in (sg.WIN_CLOSED, 'Exit'):
            break
        elif event.startswith('Do') and not thread:
            print('Thread Starting! Long work....sending value of {} seconds'.format(float(values['-SECONDS-'])))
            thread = threading.Thread(target=long_operation_thread, args=(float(values['-SECONDS-']),), daemon=True)
            thread.start()
        elif event == 'Click Me':
            print('Your GUI is alive and well')

        if thread:                                          # If thread is running
            if values['-ONE CHUNK-']:                       # If one big operation, show an animated GIF
                sg.popup_animated(sg.DEFAULT_BASE64_LOADING_GIF, background_color='white', transparent_color='white', time_between_frames=100)
            else:                                           # Not one big operation, so update a progress bar instead
                window['-PROG-'].update_bar(progress, total)
            thread.join(timeout=0)
            if not thread.is_alive():                       # the thread finished
                print(f'message = {message}')
                sg.popup_animated(None)                     # stop animination in case one is running
                thread, message, progress = None, '', 0     # reset variables for next run
                window['-PROG-'].update_bar(0,0)            # clear the progress bar

    window.close() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:50,代码来源:Demo_Multithreaded_Long_Task_Simple.py

示例11: main

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def main():
    sg.theme('LightGreen')

    layout = [[sg.Text('PyInstaller EXE Creator', font='Any 15')],
              [sg.Text('Source Python File'), sg.Input(key='-sourcefile-', size=(45, 1)),
               sg.FileBrowse(file_types=(("Python Files", "*.py"),))],
              [sg.Text('Icon File'), sg.Input(key='-iconfile-', size=(45, 1)),
               sg.FileBrowse(file_types=(("Icon Files", "*.ico"),))],
              [sg.Frame('Output', font='Any 15', layout=[
                        [sg.Output(size=(65, 15), font='Courier 10')]])],
              [sg.Button('Make EXE', bind_return_key=True),
               sg.Button('Quit', button_color=('white', 'firebrick3')) ],
              [sg.Text('Made with PySimpleGUI (www.PySimpleGUI.org)', auto_size_text=True, font='Courier 8')]]

    window = sg.Window('PySimpleGUI EXE Maker', layout, auto_size_text=False, auto_size_buttons=False, default_element_size=(20,1), text_justification='right')
    # ---===--- Loop taking in user input --- #
    while True:

        event, values = window.read()
        if event in ('Exit', 'Quit', None):
            break

        source_file = values['-sourcefile-']
        icon_file = values['-iconfile-']

        icon_option = '-i "{}"'.format(icon_file) if icon_file else ''
        source_path, source_filename = os.path.split(source_file)
        workpath_option = '--workpath "{}"'.format(source_path)
        dispath_option = '--distpath "{}"'.format(source_path)
        specpath_option = '--specpath "{}"'.format(source_path)
        folder_to_remove = os.path.join(source_path, source_filename[:-3])
        file_to_remove = os.path.join(source_path, source_filename[:-3]+'.spec')
        command_line = 'pyinstaller -wF --clean "{}" {} {} {} {}'.format(source_file, icon_option, workpath_option, dispath_option, specpath_option)

        if event == 'Make EXE':
            try:
                print(command_line)
                print('Making EXE...the program has NOT locked up...')
                window.refresh()
                # print('Running command {}'.format(command_line))
                out, err = runCommand(command_line, window=window)
                shutil.rmtree(folder_to_remove)
                os.remove(file_to_remove)
                print('**** DONE ****')
            except:
                sg.PopupError('Something went wrong', 'close this window and copy command line from text printed out in main window','Here is the output from the run', out)
                print('Copy and paste this line into the command prompt to manually run PyInstaller:\n\n', command_line) 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:49,代码来源:pysimplegui-exemaker.py

示例12: the_gui

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def the_gui():
    """
    Starts and executes the GUI
    Reads data from a Queue and displays the data to the window
    Returns when the user exits / closes the window
    """

    gui_queue = queue.Queue()  # queue used to communicate between the gui and the threads

    layout = [[sg.Text('Long task to perform example')],
              [sg.Output(size=(70, 12))],
              [sg.Text('Number of seconds your task will take'),sg.Input(key='_SECONDS_', size=(5,1)), sg.Button('Do Long Task', bind_return_key=True)],
              [sg.Button('Click Me'), sg.Button('Exit')], ]

    window = sg.Window('Multithreaded Window').Layout(layout)

    # --------------------- EVENT LOOP ---------------------
    while True:
        event, values = window.Read(timeout=100)       # wait for up to 100 ms for a GUI event
        if event is None or event == 'Exit':
            break
        elif event.startswith('Do'):
            try:
                seconds = int(values['_SECONDS_'])
                print('Starting thread to do long work....sending value of {} seconds'.format(seconds))
                threading.Thread(target=long_operation_thread, args=(seconds , gui_queue,), daemon=True).start()
            except Exception as e:
                print('Error starting work thread. Did you input a valid # of seconds? You entered: %s' % values['_SECONDS_'])
        elif event == 'Click Me':
            print('Your GUI is alive and well')
        # --------------- Check for incoming messages from threads  ---------------
        try:
            message = gui_queue.get_nowait()
        except queue.Empty:             # get_nowait() will get exception when Queue is empty
            message = None              # break from the loop if no more messages are queued up

        # if message received from queue, display the message in the Window
        if message:
            print('Got a message back from the thread: ', message)

    # if user exits the window, then close the window and exit the GUI func
    window.Close()


##     ##    ###    #### ##    ##
###   ###   ## ##    ##  ###   ##
#### ####  ##   ##   ##  ####  ##
## ### ## ##     ##  ##  ## ## ##
##     ## #########  ##  ##  ####
##     ## ##     ##  ##  ##   ###
##     ## ##     ## #### ##    ## 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:53,代码来源:Demo_Multithreaded_Long_Tasks.py

示例13: main

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def main():

    MLINE_KEY = '-ML-'+sg.WRITE_ONLY_KEY        # multiline element's key. Indicate it's an output only element
    MLINE_KEY2 = '-ML2-'+sg.WRITE_ONLY_KEY        # multiline element's key. Indicate it's an output only element
    MLINE_KEY3 = '-ML3-'+sg.WRITE_ONLY_KEY        # multiline element's key. Indicate it's an output only element

    output_key = MLINE_KEY


    layout = [  [sg.Text('Multiline Color Print Demo', font='Any 18')],
                [sg.Multiline('Multiline\n', size=(80,20), key=MLINE_KEY)],
                [sg.Multiline('Multiline2\n', size=(80,20), key=MLINE_KEY2)],
                [sg.Text('Text color:'), sg.Combo(list(color_map.keys()), size=(12,20), key='-TEXT COLOR-'),
                 sg.Text('on Background color:'), sg.Combo(list(color_map.keys()), size=(12,20), key='-BG COLOR-')],
                [sg.Input('Type text to output here', size=(80,1), key='-IN-')],
                [sg.Button('Print', bind_return_key=True), sg.Button('Print short'),
                 sg.Button('Force 1'), sg.Button('Force 2'),
                 sg.Button('Use Input for colors'), sg.Button('Toggle Output Location'), sg.Button('Exit')]  ]

    window = sg.Window('Window Title', layout)

    sg.cprint_set_output_destination(window, output_key)

    while True:             # Event Loop
        event, values = window.read()
        if event == sg.WIN_CLOSED or event == 'Exit':
            break
        if event == 'Print':
            sg.cprint(values['-IN-'], text_color=values['-TEXT COLOR-'], background_color=values['-BG COLOR-'])
        elif event == 'Print short':
            sg.cprint(values['-IN-'], c=(values['-TEXT COLOR-'], values['-BG COLOR-']))
        elif event.startswith('Use Input'):
            sg.cprint(values['-IN-'], colors=values['-IN-'])
        elif event.startswith('Toggle'):
            output_key = MLINE_KEY if output_key == MLINE_KEY2 else MLINE_KEY2
            sg.cprint_set_output_destination(window, output_key)
            sg.cprint('Switched to this output element', c='white on red')
        elif event == 'Force 1':
            sg.cprint(values['-IN-'], c=(values['-TEXT COLOR-'], values['-BG COLOR-']), key=MLINE_KEY)
        elif event == 'Force 2':
            sg.cprint(values['-IN-'], c=(values['-TEXT COLOR-'], values['-BG COLOR-']), key=MLINE_KEY2)

    window.close() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:45,代码来源:Demo_Multiline_cprint_Printing.py

示例14: main

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def main():
    # Use this GUI to get your password's hash code
    def HashGeneratorGUI():
        layout = [
            [sg.Text('Password Hash Generator', size=(30, 1), font='Any 15')],
            [sg.Text('Password'), sg.Input(key='-password-')],
            [sg.Text('SHA Hash'), sg.Input('', size=(40, 1), key='hash')],
        ]

        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)

        while True:
            event, values = window.read()
            if event == sg.WIN_CLOSED:
                break

            password = values['-password-']
            try:
                password_utf = password.encode('utf-8')
                sha1hash = hashlib.sha1()
                sha1hash.update(password_utf)
                password_hash = sha1hash.hexdigest()
                window['hash'].update(password_hash)
            except:
                pass
        window.close()

    # ----------------------------- Paste this code into your program / script -----------------------------
    # determine if a password matches the secret password by comparing SHA1 hash codes
    def PasswordMatches(password, a_hash):
        password_utf = password.encode('utf-8')
        sha1hash = hashlib.sha1()
        sha1hash.update(password_utf)
        password_hash = sha1hash.hexdigest()
        return password_hash == a_hash

    login_password_hash = '6adfb183a4a2c94a2f92dab5ade762a47889a5a1'  # helloworld
    password = sg.popup_get_text(
        'Password: (type gui for other window)', password_char='*')
    if password == 'gui':                  # Remove when pasting into your program
        HashGeneratorGUI()                              # Remove when pasting into your program
        return                                          # Remove when pasting into your program
    if password and PasswordMatches(password, login_password_hash):
        print('Login SUCCESSFUL')
    else:
        print('Login FAILED!!') 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:53,代码来源:Demo_Password_Login.py

示例15: the_gui

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Input [as 别名]
def the_gui():
    """
    Starts and executes the GUI
    Reads data from a Queue and displays the data to the window
    Returns when the user exits / closes the window
    """
    sg.theme('Light Brown 3')
    gui_queue = queue.Queue()  # queue used to communicate between the gui and the threads

    layout = [[sg.Text('Long task to perform example')],
              [sg.Output(size=(70, 12))],
              [sg.Text('Number of seconds your task will take'),
                  sg.Input(key='-SECONDS-', size=(5, 1)),
                  sg.Button('Do Long Task', bind_return_key=True)],
              [sg.Button('Click Me'), sg.Button('Exit')], ]

    window = sg.Window('Multithreaded Window', layout)

    # --------------------- EVENT LOOP ---------------------
    while True:
        event, values = window.read(timeout=100)
        if event in (sg.WIN_CLOSED, 'Exit'):
            break
        elif event.startswith('Do'):
            try:
                seconds = int(values['-SECONDS-'])
                print('Thread ALIVE! Long work....sending value of {} seconds'.format(seconds))
                threading.Thread(target=long_operation_thread,
                                 args=(seconds, gui_queue,), daemon=True).start()
            except Exception as e:
                print('Error starting work thread. Bad seconds input: "%s"' %
                      values['-SECONDS-'])
        elif event == 'Click Me':
            print('Your GUI is alive and well')
        # --------------- Check for incoming messages from threads  ---------------
        try:
            message = gui_queue.get_nowait()
        except queue.Empty:             # get_nowait() will get exception when Queue is empty
            message = None              # break from the loop if no more messages are queued up

        # if message received from queue, display the message in the Window
        if message:
            print('Got a message back from the thread: ', message)

    # if user exits the window, then close the window and exit the GUI func
    window.close() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:48,代码来源:Demo_Multithreaded_Long_Tasks.py


注:本文中的PySimpleGUI.Input方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。