PyAutoGUI Click on Item that could be on any monitorFinding the index of an item given a list containing it in PythonHow to randomly select an item from a list?Is there any way to kill a Thread?How to remove items from a list while iterating?How can I count the occurrences of a list item?pyautogui crashes whenever it clicksInstalling Pygame through Pycharm or System TerminalMouse not clicking during GUI automation with pythonWhy pyautogui click not actually clickingCould not import backend 'Glfw'

Are devices supposed to automatically be removed from iCloud when all content and settings are erased?

Creating specific options in `Manipulate[]`

Why does it seem the best way to make a living is to invest in real estate?

Do my potential customers need to understand the "meaning" of a logo, or just recognize it?

Duck, duck, gone!

Windows 10 deletes lots of tiny files super slowly. Anything that can be done to speed it up?

Implementation of a Thread Pool in C++

To what degree did the Supreme Court limit Boris Johnson's ability to prorogue?

If a spaceship ran out of fuel somewhere in space between Earth and Mars, does it slowly drift off to the Sun?

Verb ending in -ん with positive meaning?

What is the logical distinction between “the same” and “equal to?”

How to compare integers in TeX?

Did Tolkien ever write about a Heaven or Hell for Men?

Why would an airline put 15 passengers at once on standby?

How deep is the liquid in a half-full hemisphere?

What is the goal of the Shiva Purana?

Can you cure a Gorgon's Petrifying Breath before it finishes turning a target to stone?

Can the President of the US limit First Amendment rights?

How to translate "it's right to leave this world better than you found it"?

Sci-fi movie with one survivor and an organism(?) recreating his memories

Earliest time frog can jump to the other side of a river in C#. Codility's task

Is it possible to take a database offline when doing a backup using an SQL job?

Why isn't there armor to protect from spells in the Potterverse?

Would a 737 pilot use flaps in nose dive?



PyAutoGUI Click on Item that could be on any monitor


Finding the index of an item given a list containing it in PythonHow to randomly select an item from a list?Is there any way to kill a Thread?How to remove items from a list while iterating?How can I count the occurrences of a list item?pyautogui crashes whenever it clicksInstalling Pygame through Pycharm or System TerminalMouse not clicking during GUI automation with pythonWhy pyautogui click not actually clickingCould not import backend 'Glfw'






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have an extra monitor plugged into my laptop many times (but not all the time) and I recently noticed that the following code:



import pyautogui
change_intense_to_calm = pyautogui.locateOnScreen('Intense.png', confidence = 0.9)
run_script_button_x, run_script_button_y = pyautogui.center(change_intense_to_calm)
pyautogui.click(run_script_button_x, run_script_button_y)


doesn't work when the 'Intense.png" item appears on the second monitor! It does move the mouse to the position and click if it appears on the primary monitor (the laptop screen), but if the window containing that item is on the secondary monitor, it fails, giving me this error:



Traceback (most recent call last):
File "E:Installation3_IncludePK2_ScriptsAutoHotkeyfoobarFacetsSwitcherdoit.py", line 18, in <module>
run_script_button_x, run_script_button_y = pyautogui.center(change_intense_to_calm)
File "C:Program FilesPythonPython37libsite-packagespyscreeze__init__.py", line 407, in center
return (coords[0] + int(coords[2] / 2), coords[1] + int(coords[3] / 2))
TypeError: 'NoneType' object is not subscriptable


presumably because it's not finding it.



How can I modify my code so that it will find the item and click it regardless of which monitor the window containing it is located on? For reference, I am on Windows 10 64bit build 14393.










share|improve this question
































    1















    I have an extra monitor plugged into my laptop many times (but not all the time) and I recently noticed that the following code:



    import pyautogui
    change_intense_to_calm = pyautogui.locateOnScreen('Intense.png', confidence = 0.9)
    run_script_button_x, run_script_button_y = pyautogui.center(change_intense_to_calm)
    pyautogui.click(run_script_button_x, run_script_button_y)


    doesn't work when the 'Intense.png" item appears on the second monitor! It does move the mouse to the position and click if it appears on the primary monitor (the laptop screen), but if the window containing that item is on the secondary monitor, it fails, giving me this error:



    Traceback (most recent call last):
    File "E:Installation3_IncludePK2_ScriptsAutoHotkeyfoobarFacetsSwitcherdoit.py", line 18, in <module>
    run_script_button_x, run_script_button_y = pyautogui.center(change_intense_to_calm)
    File "C:Program FilesPythonPython37libsite-packagespyscreeze__init__.py", line 407, in center
    return (coords[0] + int(coords[2] / 2), coords[1] + int(coords[3] / 2))
    TypeError: 'NoneType' object is not subscriptable


    presumably because it's not finding it.



    How can I modify my code so that it will find the item and click it regardless of which monitor the window containing it is located on? For reference, I am on Windows 10 64bit build 14393.










    share|improve this question




























      1












      1








      1








      I have an extra monitor plugged into my laptop many times (but not all the time) and I recently noticed that the following code:



      import pyautogui
      change_intense_to_calm = pyautogui.locateOnScreen('Intense.png', confidence = 0.9)
      run_script_button_x, run_script_button_y = pyautogui.center(change_intense_to_calm)
      pyautogui.click(run_script_button_x, run_script_button_y)


      doesn't work when the 'Intense.png" item appears on the second monitor! It does move the mouse to the position and click if it appears on the primary monitor (the laptop screen), but if the window containing that item is on the secondary monitor, it fails, giving me this error:



      Traceback (most recent call last):
      File "E:Installation3_IncludePK2_ScriptsAutoHotkeyfoobarFacetsSwitcherdoit.py", line 18, in <module>
      run_script_button_x, run_script_button_y = pyautogui.center(change_intense_to_calm)
      File "C:Program FilesPythonPython37libsite-packagespyscreeze__init__.py", line 407, in center
      return (coords[0] + int(coords[2] / 2), coords[1] + int(coords[3] / 2))
      TypeError: 'NoneType' object is not subscriptable


      presumably because it's not finding it.



      How can I modify my code so that it will find the item and click it regardless of which monitor the window containing it is located on? For reference, I am on Windows 10 64bit build 14393.










      share|improve this question
















      I have an extra monitor plugged into my laptop many times (but not all the time) and I recently noticed that the following code:



      import pyautogui
      change_intense_to_calm = pyautogui.locateOnScreen('Intense.png', confidence = 0.9)
      run_script_button_x, run_script_button_y = pyautogui.center(change_intense_to_calm)
      pyautogui.click(run_script_button_x, run_script_button_y)


      doesn't work when the 'Intense.png" item appears on the second monitor! It does move the mouse to the position and click if it appears on the primary monitor (the laptop screen), but if the window containing that item is on the secondary monitor, it fails, giving me this error:



      Traceback (most recent call last):
      File "E:Installation3_IncludePK2_ScriptsAutoHotkeyfoobarFacetsSwitcherdoit.py", line 18, in <module>
      run_script_button_x, run_script_button_y = pyautogui.center(change_intense_to_calm)
      File "C:Program FilesPythonPython37libsite-packagespyscreeze__init__.py", line 407, in center
      return (coords[0] + int(coords[2] / 2), coords[1] + int(coords[3] / 2))
      TypeError: 'NoneType' object is not subscriptable


      presumably because it's not finding it.



      How can I modify my code so that it will find the item and click it regardless of which monitor the window containing it is located on? For reference, I am on Windows 10 64bit build 14393.







      python python-3.x automation pyautogui






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 30 at 16:43







      jippyjoe4

















      asked Mar 28 at 19:44









      jippyjoe4jippyjoe4

      2941 silver badge9 bronze badges




      2941 silver badge9 bronze badges

























          0






          active

          oldest

          votes














          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55405728%2fpyautogui-click-on-item-that-could-be-on-any-monitor%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55405728%2fpyautogui-click-on-item-that-could-be-on-any-monitor%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript