當前位置: 首頁>>代碼示例>>Python>>正文


Python PySimpleGUI.Window方法代碼示例

本文整理匯總了Python中PySimpleGUI.Window方法的典型用法代碼示例。如果您正苦於以下問題:Python PySimpleGUI.Window方法的具體用法?Python PySimpleGUI.Window怎麽用?Python PySimpleGUI.Window使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PySimpleGUI的用法示例。


在下文中一共展示了PySimpleGUI.Window方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_new_window

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [as 別名]
def create_new_window(self, window, flip=False):
        """ Close the window param just before turning the new window """

        loc = window.CurrentLocation()
        window.Disable()
        if flip:
            self.is_user_white = not self.is_user_white

        layout = self.build_main_layout(self.is_user_white)

        w = sg.Window('{} {}'.format(APP_NAME, APP_VERSION),
            layout,
            default_button_element_size=(12, 1),
            auto_size_buttons=False,
            location=(loc[0], loc[1]),
            icon=ico_path[platform]['pecg'])

        # Initialize White and black boxes
        while True:
            button, value = w.Read(timeout=50)
            self.update_labels_and_game_tags(w, human=self.username)
            break

        window.Close()
        return w 
開發者ID:fsmosca,項目名稱:Python-Easy-Chess-GUI,代碼行數:27,代碼來源:python_easy_chess_gui.py

示例2: test_get_dell_smart_attributes

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [as 別名]
def test_get_dell_smart_attributes(nvme0):
    import PySimpleGUI as sg
    
    smart = d.Buffer()
    nvme0.getlogpage(0xCA, smart, 512).waitdone()

    l = []
    l.append('Byte |  Value  | Attribute')
    l.append('   0 |  %5d  | Re-Assigned Sector Count' % smart.data(0))
    l.append('   1 |  %5d  | Program Fail Count (Worst Case Component)' % smart.data(1))
    l.append('   2 |  %5d  | Program Fail Count (SSD Total)' % smart.data(2))
    l.append('   3 |  %5d  | Erase Fail Count (Worst Case Component)' % smart.data(3))
    l.append('   4 |  %5d  | Erase Fail Count (SSD Total)' % smart.data(4))
    l.append('   5 |  %5d  | Wear Leveling Count' % smart.data(5))
    l.append('   6 |  %5d  | Used Reserved Block Count (Worst Case Component)' % smart.data(6))
    l.append('   7 |  %5d  | Used Reserved Block Count (SSD Total)' % smart.data(7))
    l.append('11:8 |  %5d  | Reserved Block Count (SSD Total)' % smart.data(11, 8))

    layout = [[sg.Listbox(l, size=(70, 10))]]
    sg.Window("Dell SMART Attributes",
              layout+[[sg.OK()]],
              font=('monospace', 16)).Read() 
開發者ID:pynvme,項目名稱:pynvme,代碼行數:24,代碼來源:test_utilities.py

示例3: ShowMeTheButtons

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [as 別名]
def ShowMeTheButtons():

    sg.SetOptions(auto_size_buttons=True, margins=(0,0), button_color=sg.COLOR_SYSTEM_DEFAULT)

    toolbar_buttons = [[sg.RButton('', image_data=get_image_bytes(close64),button_color=('white', 'black'), pad=(0,0), key='_close_'),
                        sg.RButton('', image_data=get_image_bytes(timer64), button_color=('white', 'black'), pad=(0, 0), key='_timer_'),
                        sg.RButton('', image_data=get_image_bytes(house64), button_color=('white', 'black'), pad=(0, 0), key='_house_'),
                        ]]

    # layout = toolbar_buttons
    layout =  [[sg.Frame('Launcher', toolbar_buttons,title_color='white', background_color='black')]]

    window = sg.Window('Toolbar', no_titlebar=True, grab_anywhere=True, background_color='black').Layout(layout)

    # ---===--- Loop taking in user input --- #
    while True:
        button, value = window.Read()
        print(button)
        if button == '_close_' or button is None:
            break       # exit button clicked
        elif button == '_timer_':
            pass        # add your call to launch a timer program
        elif button == '_cpu_':
            pass        # add your call to launch a CPU measuring utility 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:26,代碼來源:Demo_Floating_Toolbar_Includes_Buttons.py

示例4: main

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [as 別名]
def main():
    layout = [[sg.Graph((600,450),(0,450), (600,0), key='_GRAPH_', enable_events=True, drag_submits=True)],]

    window = sg.Window('Demo Application - OpenCV Integration', layout)

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

    id = None
    # ---===--- Event LOOP Read and display frames, operate the GUI --- #
    cap = cv2.VideoCapture(0)
    while True:
        event, values = window.Read(timeout=0)
        if event in ('Exit', None):
            break

        ret, frame = cap.read()
        imgbytes=cv2.imencode('.png', frame)[1].tobytes()
        if id:
            graph_elem.DeleteFigure(id)             # delete previous image
        id = graph_elem.DrawImage(data=imgbytes, location=(0,0))    # draw new image
        graph_elem.TKCanvas.tag_lower(id)           # move image to the "bottom" of all other drawings

        if event == '_GRAPH_':
            graph_elem.DrawCircle(values['_GRAPH_'], 5, fill_color='red', line_color='red')
    window.Close() 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:27,代碼來源:Demo_OpenCV_Draw_On_Webcam_Image.py

示例5: custom_meter_example

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [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

示例6: CustomMeter

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [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(layout)
    progress_bar = window.FindElement('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.UpdateBar(i+1)
    # done with loop... need to destroy the window as it's still open
    window.CloseNonBlocking() 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:21,代碼來源:Demo_Machine_Learning.py

示例7: PlayerChooseSongGUI

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [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

示例8: __init__

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [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

示例9: show_all_colors_on_buttons

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [as 別名]
def show_all_colors_on_buttons():
    global reverse
    global colorhex
    global colors
    window = sg.Window('Colors on Buttons Demo', default_element_size=(3, 1), location=(0, 0), icon=MY_WINDOW_ICON, font=("Helvetica", 7))
    row = []
    row_len = 20
    for i, c in enumerate(colors):
        hex = get_hex_from_name(c)
        button1 = sg.CButton(button_text=c, button_color=(get_complementary_hex(hex), hex), size=(8, 1))
        button2 = sg.CButton(button_text=c, button_color=(hex, get_complementary_hex(hex)), size=(8, 1))
        row.append(button1)
        row.append(button2)
        if (i+1) % row_len == 0:
            window.AddRow(*row)
            row = []
    if row != []:
        window.AddRow(*row)
    window.Show() 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:21,代碼來源:Demo_Color.py

示例10: main

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [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

示例11: main

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [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

示例12: main

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [as 別名]
def main():
    layout = [[sg.Graph((600,450),(0,450), (600,0), key='-GRAPH-', enable_events=True, drag_submits=True)],]

    window = sg.Window('Demo Application - OpenCV Integration', layout)
    graph_elem = window['-GRAPH-']      # type: sg.Graph
    a_id = None
    # ---===--- Event LOOP Read and display frames, operate the GUI --- #
    cap = cv2.VideoCapture(0)
    while True:
        event, values = window.read(timeout=0)
        if event in ('Exit', None):
            break

        ret, frame = cap.read()
        imgbytes=cv2.imencode('.png', frame)[1].tobytes()
        if a_id:
            graph_elem.delete_figure(a_id)             # delete previous image
        a_id = graph_elem.draw_image(data=imgbytes, location=(0,0))    # draw new image
        graph_elem.TKCanvas.tag_lower(a_id)           # move image to the "bottom" of all other drawings

        if event == '-GRAPH-':
            graph_elem.draw_circle(values['-GRAPH-'], 5, fill_color='red', line_color='red')

    window.close() 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:26,代碼來源:Demo_OpenCV_Draw_On_Webcam_Image.py

示例13: sg_show_hex_buffer

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [as 別名]
def sg_show_hex_buffer(buf):
    import PySimpleGUI as sg
    layout = [ [sg.OK(), sg.Cancel()],
               [sg.Multiline(buf.dump(),
                             enter_submits=True,
                             disabled=True, 
                             size=(80, 25))]
             ]
    sg.Window(str(buf), layout, font=('monospace', 12)).Read() 
開發者ID:pynvme,項目名稱:pynvme,代碼行數:11,代碼來源:test_utilities.py

示例14: table_example

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [as 別名]
def table_example():

    filename = sg.PopupGetFile('Get required file', no_window = True,file_types=(("CSV Files","*.csv"),))


    data = []
    header_list = []

    with open(filename, "r") as infile:    
        reader = csv.reader(infile)
        for i in range (1):                
            header = next(reader)
            data = list(reader)          
    header = header + ['%', 'Pts']         
    for i in range (len(data)):
 
        percent = int(data[i][5])/int(data[i][6])*100
        data[i] = data[i] + [percent]
        
        pts = int(data[i][2])*4 + int(data[i][4])*2
        data[i] = data[i] + [pts]        

    data.sort(key = operator.itemgetter(7), reverse = True)    
    data.sort(key = operator.itemgetter(8), reverse = True)     

    for i in range(len(data)):
        data[i][7] = str('{:.2f}'.format(data[i][7]))

    col_layout = [[sg.Table(values=data, headings=header, col_widths = (16, 3,3,3,3,6,6,6,4), auto_size_columns=False,
                    max_col_width = 30,justification='right', size=(None, len(data)))]]

    layout = [[sg.Column(col_layout, size=(480,360), scrollable=True)],]

    window = sg.Window('Table', no_titlebar = False, location = (350, 318), grab_anywhere = False).Layout(layout)
    b, v = window.Read() 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:37,代碼來源:8d PSG (Tables - add logo).py

示例15: table_example

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Window [as 別名]
def table_example():

    filename = sg.PopupGetFile('Get required file', no_window = True,file_types=(("CSV Files","*.csv"),))


    data = []
    header_list = []

    with open(filename, "r") as infile:    
        reader = csv.reader(infile)
        for i in range (1):                
            header = next(reader)
            data = list(reader)          
    header = header + ['%', 'Pts']         
    for i in range (len(data)):
 
        percent = int(data[i][5])/int(data[i][6])*100
        data[i] = data[i] + [percent]     
        pts = int(data[i][2])*4 + int(data[i][4])*2
        data[i] = data[i] + [pts]        

    data.sort(key = operator.itemgetter(7), reverse = True)    
    data.sort(key = operator.itemgetter(8), reverse = True)     

    for i in range(len(data)):
        data[i][7] = str('{:.2f}'.format(data[i][7]))

    col_layout = [[sg.Table(values=data, headings=header, auto_size_columns=True,
                    max_col_width = 12,justification='right', text_color = 'White',
                            alternating_row_color = 'Grey', size=(None, len(data)))]]

    layout = [[sg.Column(col_layout, size=(443,400), scrollable=True)],]
    window = sg.Window('Table', location = (662, 328), no_titlebar=True, grab_anywhere=False).Layout(layout)
    b, v = window.Read() 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:36,代碼來源:8d PSG (Tables - add logo).py


注:本文中的PySimpleGUI.Window方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。