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


Python pyautogui.locateOnScreen方法代码示例

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


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

示例1: open_firefox

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import locateOnScreen [as 别名]
def open_firefox():

    # Printing basic message
    msg(1,'Opening Firefox...')

    # Location the start button
    _start_button_=pyautogui.locateOnScreen('images/start_button.png')
    _location_=pyautogui.center(_start_button_)

    # Clicking the start button
    if not  pyautogui.click(_location_):
        msg(1,'Opened start menu successfully!')
    else:
        msg(3,'Failed to open start menu!')
        ext()

    time.sleep(2)

    # Search for Firefox in the menu search
    pyautogui.typewrite('firefox')
    pyautogui.typewrite('\n')
    
    # Print message
    msg(1,'Firefox is now open and running.')


# Function used to locate GMail 
开发者ID:unix121,项目名称:gmail-generator,代码行数:29,代码来源:gmail_generator.py

示例2: send_message

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import locateOnScreen [as 别名]
def send_message(contact, message):
    """Sends message to an active slack contact
    Args:
        contact (str): contacts name on slack
        message (str): message to send to friend
    Returns:
        None
    """
    try:
        print('5 seconds to navigate to slack app..')
        time.sleep(5)

        # Use JumpTo slack feature
        pyautogui.hotkey('command', 'k')
        time.sleep(1)
        # Enter contact name in search box, click enter
        pyautogui.typewrite(contact)
        time.sleep(1)
        pyautogui.typewrite(['enter'])
        time.sleep(1)

        active = pyautogui.locateOnScreen('active_identifier.png')
        
        if not active:
            print(f'{contact} is not active, skipped contact')
            return
        
        print('Contact is active, sending message...')
        pyautogui.typewrite(['tab'])      
        pyautogui.typewrite(message)
        pyautogui.typewrite(['enter'])

    except KeyboardInterrupt:
        print('Process was cancelled..') 
开发者ID:kudeh,项目名称:automate-the-boring-stuff-projects,代码行数:36,代码来源:slack_messenger.py

示例3: auto_message

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import locateOnScreen [as 别名]
def auto_message(name, message):
    """Searches for friend on Google Hangouts and messages them."""
    print("Make sure the Google Hangout 'Conversations' page is visible and "
          "your cursor is not currently on the page.")
    time.sleep(3)

    search_bar = pyautogui.locateOnScreen('search.png')
    pyautogui.click(search_bar)
    pyautogui.typewrite(name)
    time.sleep(1)

    online_select = pyautogui.locateOnScreen('online-friend.png')
    if online_select is None:
        print('Friend not found or currently offline.')
        return
    else:
        pyautogui.doubleClick(online_select)

    attempts = 3
    while attempts > 0:
        message_box = pyautogui.locateOnScreen('message.png')
        pyautogui.click(message_box)
        pyautogui.typewrite(message)

        # If it can no longer be found it is because the message was entered.
        if pyautogui.locateOnScreen('message.png') is None:
            pyautogui.press('enter')
            pyautogui.press('esc')
            print('Message sent to {}'.format(name))
            break
        else:
            if attempts == 1:
                print('Unable to send message to {}.'.format(name))
                pyautogui.press('esc')

            else:
                print('Sending message to {} failed. Another {} attempts will '
                      'be made before moving on.'.format(name, attempts))

            attempts -= 1 
开发者ID:IFinners,项目名称:automate-the-boring-stuff-projects,代码行数:42,代码来源:im_bot.py

示例4: locate_gmail

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import locateOnScreen [as 别名]
def locate_gmail():
    
    #Sleep for a while and wait for Firefox to open
    time.sleep(3)

    # Printing message
    msg(1,'Opening Gmail...')

    # Typing the website on the browser
    pyautogui.keyDown('ctrlleft');  pyautogui.typewrite('a'); pyautogui.keyUp('ctrlleft')
    pyautogui.typewrite('https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ltmpl=default')
    pyautogui.typewrite('\n')
    
    # Wait for a while until the website responds
    time.sleep(6)

    # Print a simple message
    msg(1,'Locating the form...')

    # Locate the form
    pyautogui.press('tab')
 
    time.sleep(2)

    _gmail_ = pyautogui.locateOnScreen('images/gmail_form.png')
    formx, formy = pyautogui.center(_gmail_)
    pyautogui.click(formx, formy)
    
    # Check and print message
    if not pyautogui.click(formx, formy):
        msg(1,'Located the form.')
    else:
        msg(3,'Failed to locate the form.')
        ext()


# Function used to randomize credentials 
开发者ID:unix121,项目名称:gmail-generator,代码行数:39,代码来源:gmail_generator.py

示例5: test_locateFunctions

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import locateOnScreen [as 别名]
def test_locateFunctions(self):
        # TODO - for now, we only test that the "return None" and "raise pyautogui.ImageNotFoundException" is raised.

        pyautogui.useImageNotFoundException()
        with self.assertRaises(pyautogui.ImageNotFoundException):
            pyautogui.locate("100x100blueimage.png", "100x100redimage.png")
        # Commenting out the locateAll*() functions because they return generators, even if the image can't be found. Should they instead raise an exception? This is a question for pyscreeze's design.
        # with self.assertRaises(pyautogui.ImageNotFoundException):
        #    pyautogui.locateAll('100x100blueimage.png', '100x100redimage.png')

        # with self.assertRaises(pyautogui.ImageNotFoundException):
        #    pyautogui.locateAllOnScreen('100x100blueimage.png') # NOTE: This test fails if there is a blue square visible on the screen.
        with self.assertRaises(pyautogui.ImageNotFoundException):
            pyautogui.locateOnScreen(
                "100x100blueimage.png"
            )  # NOTE: This test fails if there is a blue square visible on the screen.
        with self.assertRaises(pyautogui.ImageNotFoundException):
            pyautogui.locateCenterOnScreen(
                "100x100blueimage.png"
            )  # NOTE: This test fails if there is a blue square visible on the screen.

        pyautogui.useImageNotFoundException(False)
        self.assertEqual(pyautogui.locate("100x100blueimage.png", "100x100redimage.png"), None)
        # self.assertEqual(pyautogui.locateAll('100x100blueimage.png', '100x100redimage.png'), None)
        # self.assertEqual(pyautogui.locateAllOnScreen('100x100blueimage.png'), None) # NOTE: This test fails if there is a blue square visible on the screen.
        self.assertEqual(
            pyautogui.locateOnScreen("100x100blueimage.png"), None
        )  # NOTE: This test fails if there is a blue square visible on the screen.
        self.assertEqual(
            pyautogui.locateCenterOnScreen("100x100blueimage.png"), None
        )  # NOTE: This test fails if there is a blue square visible on the screen. 
开发者ID:asweigart,项目名称:pyautogui,代码行数:33,代码来源:test_pyautogui.py


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