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


Python PySimpleGUI.Text方法代码示例

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


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

示例1: custom_meter_example

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Text [as 别名]
def custom_meter_example():
    # layout the form
    layout = [[sg.Text('A typical custom progress meter')],
              [sg.ProgressBar(1, orientation='h', size=(20,20), key='progress')],
              [sg.Cancel()]]

    # create the form`
    window = sg.Window('Custom Progress Meter').Layout(layout)
    progress_bar = window.FindElement('progress')
    # loop that would normally do something useful
    for i in range(10000):
        # check to see if the cancel button was clicked and exit loop if clicked
        event, values = window.Read(timeout=0)
        if event == 'Cancel' or event == None:
            break
        # update bar with loop value +1 so that bar eventually reaches the maximum
        progress_bar.UpdateBar(i+1, 10000)
    # done with loop... need to destroy the window as it's still open
    window.Close() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:21,代码来源:Demo_Progress_Meters.py

示例2: PlayerChooseSongGUI

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

        # ---------------------- DEFINION OF CHOOSE WHAT TO PLAY GUI ----------------------------

        layout = [[sg.Text('MIDI File Player', font=("Helvetica", 15), size=(20, 1), text_color='green')],
                  [sg.Text('File Selection', font=("Helvetica", 15), size=(20, 1))],
                  [sg.Text('Single File Playback', justification='right'), sg.InputText(size=(65, 1), key='midifile'), sg.FileBrowse(size=(10, 1), file_types=(("MIDI files", "*.mid"),))],
                  [sg.Text('Or Batch Play From This Folder', auto_size_text=False, justification='right'), sg.InputText(size=(65, 1), key='folder'), sg.FolderBrowse(size=(10, 1))],
                  [sg.Text('_' * 250, auto_size_text=False, size=(100, 1))],
                  [sg.Text('Choose MIDI Output Device', size=(22, 1)),
                   sg.Listbox(values=self.PortList, size=(30, len(self.PortList) + 1), key='device')],
                  [sg.Text('_' * 250, auto_size_text=False, size=(100, 1))],
                  [sg.SimpleButton('PLAY', size=(12, 2), button_color=('red', 'white'), font=("Helvetica", 15), bind_return_key=True), sg.Text(' ' * 2, size=(4, 1)), sg.Cancel(size=(8, 2), font=("Helvetica", 15))]]

        window = sg.Window('MIDI File Player', auto_size_text=False, default_element_size=(30, 1), font=("Helvetica", 12)).Layout(layout)
        self.Window = window
        return window.Read() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:19,代码来源:Demo_MIDI_Player.py

示例3: main

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

示例4: main

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

示例5: worker_thread

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Text [as 别名]
def worker_thread(thread_name, run_freq,  gui_queue):
    """
    A worker thrread that communicates with the GUI
    These threads can call functions that block withouth affecting the GUI (a good thing)
    Note that this function is the code started as each thread. All threads are identical in this way
    :param thread_name: Text name used  for displaying info
    :param run_freq: How often the thread should run in milliseconds
    :param gui_queue: Queue used to communicate with the GUI
    :return:
    """
    print('Starting thread - {} that runs every {} ms'.format(thread_name, run_freq))
    for i in itertools.count():                             # loop forever, keeping count in i as it loops
        time.sleep(run_freq/1000)                           # sleep for a while
        gui_queue.put('{} - {}'.format(thread_name, i))     # put a message into queue for GUI

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

示例6: create_settings_window

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

示例7: custom_meter_example

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Text [as 别名]
def custom_meter_example():
    # layout the form
    layout = [[sg.Text('A typical custom progress meter')],
              [sg.ProgressBar(1, orientation='h', size=(20, 20), key='progress')],
              [sg.Cancel()]]

    # create the form`
    window = sg.Window('Custom Progress Meter', layout)
    progress_bar = window['progress']
    # loop that would normally do something useful
    for i in range(10000):
        # check to see if the cancel button was clicked and exit loop if clicked
        event, values = window.read(timeout=0)
        if event == 'Cancel' or event == None:
            break
        # update bar with loop value +1 so that bar eventually reaches the maximum
        progress_bar.update_bar(i+1, 10000)
    # done with loop... need to destroy the window as it's still open
    window.close() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:21,代码来源:Demo_Progress_Meters.py

示例8: worker_thread3

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Text [as 别名]
def worker_thread3(thread_name, run_freq,  gui_queue):
    """
    A worker thread that communicates with the GUI
    These threads can call functions that block without affecting the GUI (a good thing)
    Note that this function is the code started as each thread. All threads are identical in this way
    :param thread_name: Text name used  for displaying info
    :param run_freq: How often the thread should run in milliseconds
    :param gui_queue: Queue used to communicate with the GUI
    :return:
    """
    print('Starting thread 3 - {} that runs every {} ms'.format(thread_name, run_freq))
    for i in itertools.count():                             # loop forever, keeping count in i as it loops
        time.sleep(run_freq/1000)                           # sleep for a while
        # put a message into queue for GUI
        gui_queue.put('{} - {}'.format(thread_name, i))



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

示例9: CustomMeter

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Text [as 别名]
def CustomMeter():
    # layout the form
    layout = [[sg.Text('A custom progress meter')],
              [sg.ProgressBar(1000, orientation='h',
                              size=(20, 20), key='progress')],
              [sg.Cancel()]]

    # create the form`
    window = sg.Window('Custom Progress Meter', layout)
    progress_bar = window['progress']
    # loop that would normally do something useful
    for i in range(1000):
        # check to see if the cancel button was clicked and exit loop if clicked
        event, values = window.read(timeout=0, timeout_key='timeout')
        if event == 'Cancel' or event == None:
            break
        # update bar with loop value +1 so that bar eventually reaches the maximum
        progress_bar.update_bar(i+1)
    # done with loop... need to destroy the window as it's still open
    window.CloseNonBlocking() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:22,代码来源:Demo_Machine_Learning.py

示例10: PlayerChooseSongGUI

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

        # ---------------------- DEFINION OF CHOOSE WHAT TO PLAY GUI ----------------------------

        helv = ("Helvetica", 15)
        layout = [[sg.Text('MIDI File Player', font=helv15, size=(20, 1), text_color='green')],
                  [sg.Text('File Selection', font=helv15, size=(20, 1))],
                  [sg.Text('Single File Playback', justification='right'),
                      sg.InputText(size=(65, 1), key='midifile'),
                      sg.FileBrowse(size=(10, 1), file_types=(("MIDI files", "*.mid"),))],
                  [sg.Text('Or Batch Play From This Folder', auto_size_text=False, justification='right'),
                      sg.InputText(size=(65, 1), key='folder'),
                      sg.FolderBrowse(size=(10, 1))],
                  [sg.Text('_' * 250, auto_size_text=False, size=(100, 1))],
                  [sg.Text('Choose MIDI Output Device', size=(22, 1)),
                   sg.Listbox(values=self.PortList, size=(30, len(self.PortList) + 1), default_values=(self.PortList[0],), key='device')],
                  [sg.Text('_' * 250, auto_size_text=False, size=(100, 1))],
                  [sg.SimpleButton('PLAY', size=(12, 2), button_color=('red', 'white'), font=helv15, bind_return_key=True),
                      sg.Text(' ' * 2, size=(4, 1)),
                      sg.Cancel(size=(8, 2), font=helv15)]]

        window = sg.Window('MIDI File Player', layout, auto_size_text=False, default_element_size=(30, 1), font=helv)
        self.Window = window
        return window.read() 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:26,代码来源:Demo_MIDI_Player.py

示例11: __init__

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

示例12: InfoIn

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

示例13: MediaPlayerGUI

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

示例14: PopupDropDown

# 需要导入模块: import PySimpleGUI [as 别名]
# 或者: from PySimpleGUI import Text [as 别名]
def PopupDropDown(title, text, values):
    window = sg.Window(title).Layout([[sg.Text(text)],
                                      [sg.DropDown(values, key='_DROP_')],
                                      [sg.OK(), sg.Cancel()]])
    event, values = window.Read()
    return None if event != 'OK' else values['_DROP_']


# -----------------------  Calling your PopupDropDown function ----------------------- 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:11,代码来源:Demo_Popup_Custom.py

示例15: main

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


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