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


Python PySimpleGUI.Popup方法代碼示例

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


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

示例1: update_text_box

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Popup [as 別名]
def update_text_box(self, window, msg, is_hide):
        """ Update text elements """
        best_move = None
        msg_str = str(msg)

        if not 'bestmove ' in msg_str:
            if 'info_all' in msg_str:
                info_all = ' '.join(msg_str.split()[0:-1]).strip()
                msg_line = '{}\n'.format(info_all)
                window.FindElement('search_info_all_k').Update(
                        '' if is_hide else msg_line)
        else:
            # Best move can be None because engine dies
            try:
                best_move = chess.Move.from_uci(msg.split()[1])
            except Exception:
                logging.exception('Engine sent {}.'.format(best_move))
                sg.Popup('Engine error, it sent a {} bestmove.\n'.format(
                    best_move) + 'Back to Neutral mode, it is better to '
                                 'change engine {}.'.format(
                    self.opp_id_name), icon=ico_path[platform]['pecg'],
                    title=BOX_TITLE)

        return best_move 
開發者ID:fsmosca,項目名稱:Python-Easy-Chess-GUI,代碼行數:26,代碼來源:python_easy_chess_gui.py

示例2: binary_search

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Popup [as 別名]
def binary_search():
    l = sorted_names[:]                                 
    lo = 0
    hi = len(l)-1
    found = False           
    while lo <= hi:
        mid = (lo + hi) //2     
        if l[mid] == value['_binary_']:    
            sg.Popup('Binary search\n' + l[mid] + ' found.')
            found = True            
            break                   
        elif l[mid] < value['_binary_']:
            lo = mid + 1            
        else:
            hi = mid - 1            
    if not found:           
        sg.Popup('Binary search\n' +(value['_binary_'] + ' was not found')) 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:19,代碼來源:6c PSG (search text preloaded).py

示例3: main

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Popup [as 別名]
def main():
    button, values = GetFilesToCompare()
    f1 = values['file1']
    f2 = values['file2']

    if any((button != 'Submit', f1 =='', f2 == '')):
        sg.PopupError('Operation cancelled')
        sys.exit(69)

    # --- This portion of the code is not GUI related ---
    with open(f1, 'rb') as file1:
        with open(f2, 'rb') as file2:
            a = file1.read()
            b = file2.read()

        for i, x in enumerate(a):
            if x != b[i]:
                sg.Popup('Compare results for files', f1, f2, '**** Mismatch at offset {} ****'.format(i))
                break
        else:
            if len(a) == len(b):
                sg.Popup('**** The files are IDENTICAL ****') 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:24,代碼來源:Demo_Compare_Files.py

示例4: linear_search

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Popup [as 別名]
def linear_search():
    l = names[:]
    found = False
    for l in l:
        if l == value['_linear_']:            
            found = True
            sg.Popup('Linear search\n' + l + ' found.')
            break
    if not found:
        sg.Popup('Linear search\n' +(value['_linear_'] + ' was not found'))

#Binary Search - only works for ordered lists 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:14,代碼來源:6c PSG (search text preloaded).py

示例5: pong

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

示例6: FindDuplicatesFilesInFolder

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Popup [as 別名]
def FindDuplicatesFilesInFolder(path):
    shatab = []
    total = 0
    small_count, dup_count, error_count = 0,0,0
    pngdir = path
    if not os.path.exists(path):
        sg.Popup('Duplicate Finder', '** Folder doesn\'t exist***', path)
        return
    pngfiles = os.listdir(pngdir)
    total_files = len(pngfiles)
    for idx, f in enumerate(pngfiles):
        if not sg.OneLineProgressMeter('Counting Duplicates', idx + 1, total_files, 'Counting Duplicate Files'):
            break
        total += 1
        fname = os.path.join(pngdir, f)
        if os.path.isdir(fname):
            continue
        x = open(fname, "rb").read()

        m = hashlib.sha256()
        m.update(x)
        f_sha = m.digest()
        if f_sha in shatab:
            # uncomment next line to remove duplicate files
            # os.remove(fname)
            dup_count += 1
            # sg.Print(f'Duplicate file - {f}')    # cannot current use sg.Print with Progress Meter
            continue
        shatab.append(f_sha)

    msg = '{} Files processed\n {} Duplicates found'.format(total_files, dup_count)
    sg.Popup('Duplicate Finder Ended', msg)

# ====____====____==== Pseudo-MAIN program ====____====____==== #
# This is our main-alike piece of code                          #
#   + Starts up the GUI                                         #
#   + Gets values from GUI                                      #
#   + Runs DeDupe_folder based on GUI inputs                    #
# ------------------------------------------------------------- # 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:41,代碼來源:Demo_DuplicateFileFinder.py

示例7: main

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Popup [as 別名]
def main():
    # folder = r'C:\Python\PycharmProjects\GooeyGUI\Uno Cards'
    folder=''
    folder = sg.PopupGetFolder('Source folder for images\nImages will be encoded and results saved to %s'%OUTPUT_FILENAME,
                               title='Base64 Encoder',
                               default_path=folder, initial_folder=folder )

    if folder is None or folder == '':
        sg.PopupCancel('Cancelled - No valid folder entered')
        return
    try:
        namesonly = [f for f in os.listdir(folder) if f.endswith('.png') or f.endswith('.ico') or f.endswith('.gif')]
    except:
        sg.PopupCancel('Cancelled - No valid folder entered')
        return

    outfile = open(os.path.join(folder, OUTPUT_FILENAME), 'w')

    for i, file in enumerate(namesonly):
        contents = open(os.path.join(folder, file), 'rb').read()
        encoded = base64.b64encode(contents)
        outfile.write('\n{} = {}\n\n'.format(file[:file.index(".")], encoded))
        sg.OneLineProgressMeter('Base64 Encoding', i+1, len(namesonly),key='_METER_')

    outfile.close()
    sg.Popup('Completed!', 'Encoded %s files'%(i+1)) 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:28,代碼來源:Demo_Base64_Image_Encoder.py

示例8: callback_function1

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Popup [as 別名]
def callback_function1():
    sg.Popup('In Callback Function 1')
    print('In the callback function 1') 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:5,代碼來源:Demo_Button_Func_Calls.py

示例9: callback_function2

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Popup [as 別名]
def callback_function2():
    sg.Popup('In Callback Function 2')
    print('In the callback function 2') 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:5,代碼來源:Demo_Button_Func_Calls.py

示例10: main

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Popup [as 別名]
def main():
    RemoteControlExample_NoGraphics()
    # Uncomment to get the fancy graphics version.  Be sure and download the button images!
    RemoteControlExample()
    # sg.Popup('End of non-blocking demonstration') 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:7,代碼來源:Demo_Pi_Robotics.py

示例11: the_gui

# 需要導入模塊: import PySimpleGUI [as 別名]
# 或者: from PySimpleGUI import Popup [as 別名]
def the_gui():
    gui_queue = queue.Queue()  # queue used to communicate between the gui and long-running code

    layout = [[sg.Text('Multithreaded Work Example')],
              [sg.Text('Click Go to start a long-running function call')],
              [sg.Text('', size=(25, 1), key='_OUTPUT_')],
              [sg.Text('', size=(25, 1), key='_OUTPUT2_')],
              [sg.Graph((10,10),(0,0),(10,10),background_color='black',key=i) for i in range(20)],
              [sg.Button('Go'), sg.Button('Popup'), sg.Button('Exit')], ]

    window = sg.Window('Multithreaded Window').Layout(layout)
    # --------------------- EVENT LOOP ---------------------
    work_id = 0
    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
        if event == 'Go':           # clicking "Go" starts a long running work item by starting thread
            window.Element('_OUTPUT_').Update('Starting long work %s'%work_id)
            window.Element(work_id).Update(background_color='red')
            # LOCATION 2
            # STARTING long run by starting a thread
            thread_id = threading.Thread(target=long_function_wrapper, args=(work_id, gui_queue,), daemon=True)
            thread_id.start()
            work_id = work_id+1 if work_id < 19 else 0
        # --------------- Read next message coming in from threads ---------------
        try:
            message = gui_queue.get_nowait()    # see if something has been posted to Queue
        except queue.Empty:                     # get_nowait() will get exception when Queue is empty
            message = None                      # nothing in queue so do nothing

        # if message received from queue, then some work was completed
        if message is not None:
            # LOCATION 3
            # this is the place you would execute code at ENDING of long running task
            # You can check the completed_work_id variable to see exactly which long-running function completed
            completed_work_id = int(message[:message.index(' :::')])
            window.Element('_OUTPUT2_').Update('Complete Work ID "{}"'.format(completed_work_id))
            window.Element(completed_work_id).Update(background_color='green')

        if event == 'Popup':
            sg.Popup('This is a popup showing that the GUI is running')
    # if user exits the window, then close the window and exit the GUI func
    window.Close()

############################# Main ############################# 
開發者ID:PySimpleGUI,項目名稱:PySimpleGUI,代碼行數:48,代碼來源:Demo_Threaded_Work.py


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