disable failSafeCheck Python PyAutoGui without editing the pyautogui file - python-3.x

So I'm using PyCharm as a python editor, and I don't know if it's because of my editor, but whenever I run a simple PyAutoGui program such as:
import time, pyautogui
time.sleep(3)
while True:
pyautogui.hotkey('ctrl', 'r')
time.sleep(15)
for too long, I keep getting an error (I don't have that error currently, because I usually have to wait a long time before getting the error from pyautogui. But it looks something like) :
PyAutoGUI fail-safe triggered from mouse moving to a corner of the screen.
I'm not very experienced with Python PyAutoGui module, but is there a way to disable that safe-check without doing something in the pyautogui python file?

You're in luck! Just add pyautogui.FAILSAFE = True right after importing the library.
Check out their docs it has a lot of good info.

Related

subprocess works but unexpected black screen

I'm trying to open the DellCommandUpdate with python in full screen. I can get the application to open with the first code but couldn't figure out how to maximize the screen. Someone suggested trying sub process. It comes up as a black window similar to cmd.
import os
os.startfile("C:\Program Files (x86)\Dell\CommandUpdate\DellCommandUpdate.exe")
import subprocess
subprocess.call(["cmd", "/c", "start", "/max", "C:\Program Files (x86)\Dell\CommandUpdate\DellCommandUpdate.exe"])
The goal for this is to be able to open the program to be able to click update. I'm not sure if there is something like selenium but for desktop apps or how I would program to automate this

pyautogui is not working in ubuntu 18.04 . hotkeys not working outside the editor while it works inside the editor

hello everyone i am using ubuntu 18 and python 3.6 but here is a bit of problem in pyautogui
it's writing and mouse functions are doing great but hotkeys got some problem
hotkeys are doing there jon inside the editor in my case it's pycharm but not outside the editor any kind of code for example:-
'ctrl' + 'alt' + 's' opens the settings in pycharm so the code
import pyautogui
pyautogui.hotkey("ctrl", "alt", "s")
works perfeclty
but code like
import pyautogui
pyautogui.hotkey("alt", "tab")
everyone knows what it does but it doesn't work
i've tried this also
import pyautogui
pyautogui.keyDown("alt")
pyautogui.press("tab")
pyautogui.keyUp("alt")
but same thing nothing happens
Ran into the same problem
Here's what worked for me :
pyautogui.keyDown('alt')
pyautogui.keyDown('tab')
pyautogui.keyUp('tab')
pyautogui.keyUp('alt')

Simulate multiple click on a mouse press python

So I tried to simulate multiple mouse left click whenever I press the mouse's left button.However, my mouse start teleporting/moving slowly whenever I run my code. I am actually running this code with pycharm IDE.
I thought that maybe I am sending too much command per mouse press, so I decided to add a sleep between each click, to see the behavior. Unfortunately, the program still behave the same way.
from pynput.mouse import Listener,Controller, Button
import time
mouse = Controller()
def on_click(x, y, button, pressed):
if pressed and button == Button.left:
mouse.click(Button.right,2)
time.sleep(2)
print("stop")
with Listener( on_click=on_click) as listener:
listener.join()
I know that the code is not completed yet, but my final goal would be to simulate multiple click, with an interval of ~0.05 second, while I hold the mouse's left button.
Thank you,
Try using pyautogui rather than pynput.mouse.
Quick heads up I am not that good at python. Also, I know I am late because it's been over a year already but if this is not for you, it is also for future people who stumble upon this question/question in the future.
Before you look at the code and run it, we need to do one pip install.
In the console/terminal type
pip install pyautogui
In your case, you are using PyCharm. Just install the package pyautogui
Great! Now you are ready to look at the code:
import pyautogui
#You can change the clicks.
pyautogui.click(clicks=10)
For what you said about simulating an interval of 0.05 per second. I don't know how to help you there. Maybe try trial and error.
import pyautogui
seconds_for_clicking = 5
#This is for converting to actual seconds
seconds_for_clicking = seconds_for_clicking * 9
for i in range(seconds_for_clicking):
#You can change the clicks.
pyautogui.click(clicks=10)
#Maybe try this. In this case I think that you have to try trial and error. Change the number to whatever you want.
time.sleep(0.05)
``
Hope this helps :D

pyttsx3 is conflicting with tkinter

My tkinter app will run console-free (.pyw) until I import pyttsx3. As soon as pyttsx3 is imported, the app will only run from the editor (Idle).
This is a tkinter app that runs perfectly when run from idle. I import pyttsx3, initialize it, have it speak using Windows Sapi voices, all is well, all tkinter functions operate as intended from start to finish. But outside of Idle, the app won't run in .pyw mode. It shows a black console screen for a brief moment and closes. I have checked very carefully - removing all pyttsx3 code from the app - except the import statement and, quite literally, the import statement alone is enough to cause the app to no longer run in .pyw mode.
import tkinter as tk
(runs fine in .pyw mode)
import tkinter as tk
import pyttsx3 as speak
(will not run in .pyw mode)
The question: how could simply importing a library (not even initializing or using it...just importing it) cause the tkinter app to no longer run as .pyw? Could importing a library somehow be interfering with the tkinter main loop?
Good question. If I had to guess, something in the pyttsx3 library invokes a process that is unrelated to Python, for the purpose of text-to-speech conversion. Windows probably opens a Command Prompt window in such a case since that process runs independently.
Unless the pyttsx3 library has documentation for how to suppress this—after a cursory glance, I don't see such—then I would recommend opening a new issue with the package maintainer. I believe that it would need to set the CREATE_NO_WINDOW flag when being run on Windows.

Clear screen with CMD disabled

I'm trying to clear the screen in my Idle text editor (the default one that comes with python (and is basically command prompt anyway).
I have had this problem for a while now and i've searched just about every corner of the web but nothing has truly answered my problem.
import subprocess
import subprocess as sp
import os
os.system('cls')
does not work
Ctrl + L does not work
clearing modules also do not work
Using this for loading screens, animations etc... would be a dream com true so if anyone can find a way to do this it would be much appreciated.

Resources