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


Python PySimpleGUI.Button方法代码示例

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


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

示例1: __init__

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Button [as 别名]
def __init__(self, location=(None, None), font=('Arial', 16)):
        self.font = font
        numberRow = '1234567890'
        topRow = 'QWERTYUIOP'
        midRow = 'ASDFGHJKL'
        bottomRow = 'ZXCVBNM'
        keyboard_layout = [[sg.Button(c, key=c, size=(4, 2), font=self.font) for c in numberRow] + [
            sg.Button('⌫', key='back', size=(4, 2), font=self.font),
            sg.Button('Esc', key='close', size=(4, 2), font=self.font)],
                           [sg.T(' ' * 4)] + [sg.Button(c, key=c, size=(4, 2), font=self.font) for c in
                                              topRow] + [sg.Stretch()],
                           [sg.T(' ' * 11)] + [sg.Button(c, key=c, size=(4, 2), font=self.font) for c in
                                               midRow] + [sg.Stretch()],
                           [sg.T(' ' * 18)] + [sg.Button(c, key=c, size=(4, 2), font=self.font) for c in
                                               bottomRow] + [sg.Stretch()]]

        self.window = sg.Window('keyboard',
                                grab_anywhere=True,
                                keep_on_top=True,
                                alpha_channel=0,
                                no_titlebar=True,
                                element_padding=(0,0),
                                location=location
                                ).Layout(keyboard_layout).Finalize()
        self.hide() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:27,代码来源:Demo_Touch_Keyboard.py

示例2: main

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Button [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 Button [as 别名]
def main():
    layout = [[sg.Text('A toggle button example')],
              [sg.T('A graphical version'), sg.B('', image_data=toggle_btn_off, key='_TOGGLE_GRAPHIC_', button_color=sg.COLOR_SYSTEM_DEFAULT,border_width=0),],
              [sg.Button('On', size=(3,1), button_color=('white', 'green'), key='_B_'), sg.Button('Exit')]]

    window = sg.Window('Toggle Button Example', layout)

    down = True
    graphic_off = True
    while True:             # Event Loop
        event, values = window.Read()
        print(event, values)
        if event in (None, 'Exit'):
            break
        elif event == '_B_':                # if the normal button that changes color and text
            down = not down
            window.Element('_B_').Update(('Off','On')[down], button_color=(('white', ('red', 'green')[down])))
        elif event == '_TOGGLE_GRAPHIC_':   # if the graphical button that changes images
            graphic_off = not graphic_off
            window.Element('_TOGGLE_GRAPHIC_').Update(image_data=(toggle_btn_on, toggle_btn_off)[graphic_off])

    window.Close() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:24,代码来源:Demo_Button_Toggle.py

示例4: create_settings_window

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Button [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

示例5: main

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Button [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

示例6: main

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

    col = [[sg.Text('This is the first line')],
           [sg.In()],
           [sg.Button('Save'), sg.Button('Exit')]]

    layout = [[sg.Column(col, key='-COLUMN-')]]     # put entire layout into a column so it can be saved

    window = sg.Window("Drawing and Moving Stuff Around", layout)

    while True:
        event, values = window.read()
        if event in (sg.WIN_CLOSED, 'Exit'):
            break  # exit
        elif event == 'Save':
            filename = sg.popup_get_file('Choose file (PNG, JPG, GIF) to save to', save_as=True)
            save_element_as_file(window['-COLUMN-'], filename)

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

示例7: __init__

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Button [as 别名]
def __init__(self, location=(None, None), font=('Arial', 16)):
        self.font = font
        numberRow = '1234567890'
        topRow = 'QWERTYUIOP'
        midRow = 'ASDFGHJKL'
        bottomRow = 'ZXCVBNM'
        keyboard_layout = [[sg.Button(c, key=c, size=(4, 2), font=self.font) for c in numberRow] + [
            sg.Button('⌫', key='back', size=(4, 2), font=self.font),
            sg.Button('Esc', key='close', size=(4, 2), font=self.font)],
            [sg.Text(' ' * 4)] + [sg.Button(c, key=c, size=(4, 2), font=self.font) for c in
                               topRow] + [sg.Stretch()],
            [sg.Text(' ' * 11)] + [sg.Button(c, key=c, size=(4, 2), font=self.font) for c in
                                midRow] + [sg.Stretch()],
            [sg.Text(' ' * 18)] + [sg.Button(c, key=c, size=(4, 2), font=self.font) for c in
                                bottomRow] + [sg.Stretch()]]

        self.window = sg.Window('keyboard', keyboard_layout,
                                grab_anywhere=True, keep_on_top=True, alpha_channel=0,
                                no_titlebar=True, element_padding=(0, 0), location=location, finalize=True)
        self.hide() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:22,代码来源:Demo_Touch_Keyboard.py

示例8: render_square

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Button [as 别名]
def render_square(self, image, key, location):
        """ Returns an RButton (Read Button) with image image """
        if (location[0] + location[1]) % 2:
            color = self.sq_dark_color  # Dark square
        else:
            color = self.sq_light_color
        return sg.RButton('', image_filename=image, size=(1, 1),
                          border_width=0, button_color=('white', color),
                          pad=(0, 0), key=key) 
开发者ID:fsmosca,项目名称:Python-Easy-Chess-GUI,代码行数:11,代码来源:python_easy_chess_gui.py

示例9: MediaPlayerGUI

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Button [as 别名]
def MediaPlayerGUI():
    background = '#F0F0F0'
    # Set the backgrounds the same as the background on the buttons
    sg.SetOptions(background_color=background, element_background_color=background)
    # Images are located in a subfolder in the Demo Media Player.py folder
    image_pause = './ButtonGraphics/Pause.png'
    image_restart = './ButtonGraphics/Restart.png'
    image_next = './ButtonGraphics/Next.png'
    image_exit = './ButtonGraphics/Exit.png'

    # A text element that will be changed to display messages in the GUI

    ImageButton = lambda image_filename, key:sg.Button('', button_color=(background,background), image_filename=image_filename, image_size=(50, 50), image_subsample=2, border_width=0, key=key)

    # define layout of the rows
    layout= [[sg.Text('Media File Player', font=("Helvetica", 25))],
             [sg.Text('', size=(15, 2), font=("Helvetica", 14), key='output')],
             [ImageButton(image_restart, key='Restart Song'), sg.Text(' ' * 2),
              ImageButton(image_pause, key='Pause'),
                                sg.Text(' ' * 2),
              ImageButton(image_next, key='Next'),
                                sg.Text(' ' * 2),
              sg.Text(' ' * 2),ImageButton(image_exit, key='Exit')],
             ]

    # Open a form, note that context manager can't be used generally speaking for async forms
    window = sg.Window('Media File Player', auto_size_text=True, default_element_size=(20, 1),
                       font=("Helvetica", 25)).Layout(layout)
    # Our event loop
    while(True):
        event, values = window.Read(timeout=100)        # Poll every 100 ms
        if event == 'Exit' or event is None:
            break
        # If a button was pressed, display it on the GUI by updating the text element
        if event != sg.TIMEOUT_KEY:
            window.FindElement('output').Update(event) 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:38,代码来源:Demo_Media_Player.py

示例10: main

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

    # define the form layout
    layout = [[ sg.Canvas(size=SIZE, background_color='white',key='canvas') , sg.Button('Exit', pad=(0, (210, 0)))]]

    # create the form and show it without the plot
    window = sg.Window('Ping Graph', background_color='white', grab_anywhere=True).Layout(layout).Finalize()

    canvas_elem = window.FindElement('canvas')
    canvas = canvas_elem.TKCanvas

    fig = plt.figure(figsize=(3.1, 2.25), tight_layout={'pad':0})
    g_my_globals.axis_ping = fig.add_subplot(1,1,1)
    plt.rcParams['xtick.labelsize'] = 8
    plt.rcParams['ytick.labelsize'] = 8
    set_chart_labels()
    plt.tight_layout()

    while True:
        event, values = window.Read(timeout=0)
        if event in ('Exit', None):
            exit(0)

        run_a_ping_and_graph()
        photo = draw(fig, canvas) 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:28,代码来源:Demo_Matplotlib_Ping_Graph.py

示例11: pong

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Button [as 别名]
def pong():
    layout = [[sg.Graph(GAMEPLAY_SIZE, (0,GAMEPLAY_SIZE[1]), (GAMEPLAY_SIZE[0],0), background_color=BACKGROUND_COLOR, key='_GRAPH_')],
              [sg.T(''), sg.Button('Exit'), sg.T('Speed'), sg.Slider((0,20),default_value=10, orientation='h', enable_events=True, key='_SPEED_')]]

    window = sg.Window('Pong', layout, return_keyboard_events=True).Finalize()

    graph_elem = window.FindElement('_GRAPH_')                  # type: sg.Graph

    bat_1 = PongBat(graph_elem, 'red', 30)
    bat_2 = PongBat(graph_elem, 'blue', 670)

    ball_1 = Ball(graph_elem, bat_1, bat_2, 'green1')
    sleep_time = 10

    while True:
        ball_1.draw()
        bat_1.draw()
        bat_2.draw()

        event, values = window.Read(timeout=sleep_time)         # type: str, str
        if event is None or event == 'Exit':
            break
        elif event.startswith('Up') or event.endswith('Up'):
            bat_2.up(5)
        elif event.startswith('Down') or event.endswith('Down'):
            bat_2.down(5)
        elif event == 'w':
            bat_1.up(5)
        elif event == 's':
            bat_1.down(5)
        elif event == '_SPEED_':
            sleep_time = int(values['_SPEED_'])

        if ball_1.win_loss_check():
            sg.Popup('Game Over', ball_1.win_loss_check() + ' won!!')
            break
    window.Close() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:39,代码来源:Demo_Pong_Multiple_Platforms.py

示例12: main

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

    NUM_DATAPOINTS = 10000
    # define the form layout
    layout = [[sg.Text('Animated Matplotlib', size=(40, 1), justification='center', font='Helvetica 20')],
              [sg.Canvas(size=(640, 480), key='-CANVAS-')],
              [sg.Text('Progress through the data')],
              [sg.Slider(range=(0, NUM_DATAPOINTS), size=(60, 10), orientation='h', key='-SLIDER-')],
              [sg.Text('Number of data points to display on screen')],
               [sg.Slider(range=(10, 500), default_value=40, size=(40, 10), orientation='h', key='-SLIDER-DATAPOINTS-')],
              [sg.Button('Exit', size=(10, 1), pad=((280, 0), 3), font='Helvetica 14')]]

    # create the form and show it without the plot
    window = sg.Window('Demo Application - Embedding Matplotlib In PySimpleGUI', layout, finalize=True)

    canvas_elem = window.FindElement('-CANVAS-')
    slider_elem = window.FindElement('-SLIDER-')
    canvas = canvas_elem.TKCanvas

    # draw the initial plot in the window
    fig = Figure()
    ax = fig.add_subplot(111)
    ax.set_xlabel("X axis")
    ax.set_ylabel("Y axis")
    ax.grid()
    fig_agg = draw_figure(canvas, fig)
    # make a bunch of random data points
    dpts = [randint(0, 10) for x in range(NUM_DATAPOINTS)]

    for i in range(len(dpts)):
        event, values = window.Read(timeout=10)
        if event in ('Exit', None):
            exit(69)
        slider_elem.Update(i)       # slider shows "progress" through the data points
        ax.cla()                    # clear the subplot
        ax.grid()                   # draw the grid
        data_points = int(values['-SLIDER-DATAPOINTS-']) # draw this many data points (on next line)
        ax.plot(range(data_points), dpts[i:i+data_points],  color='purple')
        fig_agg.draw() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:41,代码来源:Demo_Matplotlib_Animated.py

示例13: main

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

    # define the form layout
    layout = [[sg.Text('Animated Ping', size=(40, 1), justification='center', font='Helvetica 20')],
              [sg.Canvas(size=(640, 480), key='canvas')],
              [sg.Button('Exit', size=(10, 2), pad=((280, 0), 3), font='Helvetica 14')]]

    # create the form and show it without the plot
    window = sg.Window('Demo Application - Embedding Matplotlib In PySimpleGUI').Layout(layout).Finalize()

    canvas_elem = window.FindElement('canvas')
    canvas = canvas_elem.TKCanvas

    fig = plt.figure()
    g_my_globals.axis_ping = fig.add_subplot(1,1,1)
    set_chart_labels()
    plt.tight_layout()

    while True:
        event, values = window.Read(timeout=0)
        if event in ('Exit', None):
            break

        run_a_ping_and_graph()
        photo = draw(fig, canvas) 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:28,代码来源:Demo_Matplotlib_Ping_Graph_Large.py

示例14: DownloadSubtitlesGUI

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Button [as 别名]
def DownloadSubtitlesGUI():
    sg.ChangeLookAndFeel('Dark')

    combobox = sg.InputCombo(values=['',], size=(10,1), key='lang')
    layout =  [
                [sg.Text('Subtitle Grabber', size=(40, 1), font=('Any 15'))],
                [sg.T('YouTube Link'),sg.In(default_text='',size=(60,1), key='link', do_not_clear=True) ],
                [sg.Output(size=(90,20), font='Courier 12')],
                [sg.Button('Get List')],
                [sg.T('Language Code'), combobox, sg.Button('Download')],
                [sg.Button('Exit', button_color=('white', 'firebrick3'))]
                ]

    window = sg.Window('Subtitle Grabber launcher', text_justification='r', default_element_size=(15,1), font=('Any 14')).Layout(layout)

    # ---===--- Loop taking in user input and using it to query HowDoI --- #
    while True:
        event, values = window.Read()
        if event in ('Exit', None):
            break           # exit button clicked
        link = values['link']
        if event == 'Get List':
            print('Getting list of subtitles....')
            window.Refresh()
            command = [f'C:\\Python\\Anaconda3\\Scripts\\youtube-dl.exe --list-subs {link}',]
            output = ExecuteCommandSubprocess(command, wait=True, quiet=True)
            lang_list = [o[:5].rstrip() for o in output.split('\n') if 'vtt' in o]
            lang_list = sorted(lang_list)
            combobox.Update(values=lang_list)
            print('Done')

        elif event == 'Download':
            lang = values['lang'] or 'en'
            print(f'Downloading subtitle for {lang}...')
            window.Refresh()
            command = [f'C:\\Python\\Anaconda3\\Scripts\\youtube-dl.exe --sub-lang {lang} --write-sub {link}',]
            print(ExecuteCommandSubprocess(command, wait=True, quiet=False))
            print('Done') 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:40,代码来源:Demo_Youtube-dl_Frontend.py

示例15: show_win

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Button [as 别名]
def show_win():
    sg.SetOptions(border_width=0, margins=(0,0), element_padding=(5,3))


    frame_layout = [ [sg.Button('', image_data=mac_red, button_color=('white', sg.COLOR_SYSTEM_DEFAULT), key='_exit_'),
                sg.Button('', image_data=mac_orange, button_color=('white', sg.COLOR_SYSTEM_DEFAULT)),
                sg.Button('', image_data=mac_green, button_color=('white', sg.COLOR_SYSTEM_DEFAULT), key='_minimize_'),
                      sg.Text(' '*40)],]

    layout = [[sg.Frame('',frame_layout)],
               [sg.T('')],
                [ sg.Text('   My Mac-alike window', size=(25,2)) ],]

    window = sg.Window('My new window',
                       no_titlebar=True,
                       grab_anywhere=True,
                       alpha_channel=0,
                       ).Layout(layout).Finalize()

    for i in range(100):
        window.SetAlpha(i/100)
        time.sleep(.01)

    while True:     # Event Loop
        event, values = window.Read()
        if event is None or event == '_exit_':
            break
        if event == '_minimize_':
            # window.Minimize()     # cannot minimize a window with no titlebar
            pass
        print(event, values) 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:33,代码来源:Demo_Buttons_Mac.py


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