I am using the pyautogui library, and it was working...and for some reason after I reinstalled my Ubuntu system I dont manage to use it.
I show below the code, just several lines copied from the Docs.
The only information about the error, showed in picture I found is this link mentioning "BadValue error", which I dont really understand (100 and 200 are inside range)
https://tronche.com/gui/x/xlib/event-handling/protocol-errors/default-handlers.html
import pyautogui
pyautogui.moveTo(100, 200)
pyautogui.position()
pyautogui.click()
pyautogui.click(100, 200)
Thanks a lot!
Picture with code and execution error
Well, I don't know why this error is coming, because in PyCharm, it works perfectly. But I noticed that the first 3 lines are unnecessary so try this code and tell me if it helps:
from pyautogui import *
click(100, 200)
Related
From what I understand, pyautogui doesn't work properly when trying to get screenshots of my screen because I'm running Ubuntu 22.04 wayland.
I saw somewhere that you could enable Xorg again and it should work fine... however, this solution is not ideal for me.
Anyone knows any workaround for pyautogui to be able to capture proper screenshot?
Below my code to get the screenshot, but when I check the "test.png" file, it's all black.
import pyautogui as pg
x1,y1 = 1525,312
x2,y2 = 1655,370
img = pg.screenshot(region=(x1,y1,x2,y2))
img.save("test.png")
Python noob here, ive started a tkinter tutorial and no matter what method I use to change the background color it stays black. Im using vs code on mac and I made sure everything is updated. Ive also tried it in pycharm and the same problem occurs. Im not getting any errors in the terminal. Here is what I have,
from tkinter import *
window = Tk()
window.geometry("500x500")
window.title("Weather.py")
window.config(bg="blue")
window.mainloop()
Any ideas?
Update:
Tried it on another mac in the house and is seemed to work on that one. Not sure why it wont work on mine.
Link provided by #Rory did the trick... Along with several restarts of both the computer and vs code.
pyautogui's click method's issue:
I am running the script from Spyder, if I click anything on Spyder's window the click works fine.
If I execute a script to open Outlook, then click on anything, the click does not happen. Although I am able to use the "moveTo" functionality properly.
Things I have tried as suggested by doing google search:
pyautogui.click()
pyautogui.click()
OS : mac os high sierra
Note:
In order to reach any located image I have to do coordinates/2, as it is a Retina 2x display.
Any workaround or any help will be greatly appreciated.
To anyone who might stumble into the same issue on a Mac, I was able to get it working by using a workaround that is using the pynput library.
Code:
import pyautogui
from pynput.mouse import Button, Controller
mouse = Controller()
pyautogui.moveTo(x,y)
mouse.click(Button.left)
OS X Mojave, the following works for me:
pyautogui.moveTo(pos)
pyautogui.dragTo(button='left')
pyautogui.click() throws an attribute error but pyautogui.dragTo() works instead.
I just found out that in mac setting, I did not check the tip in front of PyCharm in privacy setting. After doing that, my pyautogui.click() function works.
I was also facing same issue, Here is what I tried :
Just add one more line pyautogui.dragTo() to focus on that particular selected area:
pyautogui.moveTo(990,28)
pyautogui.dragTo()
pyautogui.click()
I'm new to the turtle module and I'm having a problem while setting a background pic for my turtle project.
when running this code:
import turtle as tr
import os
os.chdir(pathname)
tr.setup(400,400)
tr.bgpic("diamond.gif")
I get an error message for the 5th line ending with:
_tkinter.TclError: image "pyimage4" doesn't exist
Sometimes it's pyimage2 doesn't exist or pyimage36. At each execution it changes.
I didn't find a real solution in other posts. Any help will be much appreciated.
You're not showing us your actual minimal code that fails as your example doesn't get past this line:
os.chdir(pathname)
since pathname isn't defined. I downloaded this GIF, renamed it diamond.gif, and ran the following subset of your code:
import turtle as tr
tr.setup(400, 400)
tr.bgpic("diamond.gif")
tr.done()
This displays the GIF in a window:
If you repeat what I did, and it works, then this may be a problem with your GIF file. (Download the GIF from this link, don't use my PNG illustration above.) If you repeat what I did and it doesn't work, then it may be a problem with your environment. This error message:
_tkinter.TclError: image "pyimage4" doesn't exist
is often associated with independently initializing both the turtle and the tkinter modules. If you aren't doing such, perhaps you're running in a specially tweaked environment that is. There may be a workaround, but you first need to determine what's really happening.
This is my first question so apologies in advanced for everything I'll do wrong in the next lines.
I am having issues with the doubleClick function from pyautogui on mac with OSX.
Lately I have written some python code using the following libraries
from time import sleep
from random import uniform as r
from pyautogui import click, doubleClick, press, moveTo, mouseDown, mouseUp
from webbrowser import open_new_tab
Even by trying the simplest combination
x1, y1 = (300, 375)
doubleClick(x=x1, y=y1)
there is no action taking place. I have tried two quick clicks with an interval, both also got no results from that.
I am experiencing this as a major issues and have checked now on several mac machines (5+) and the issue is always there and I cannot find any reference in other questions or on the internet.
Is anyone else experiencing the same?
Thank you already for your help.
Had the same problem. Found a fix here. (Just make sure you first activated the window you need to double click in, with a single click. I forgot and now it works perfectly.)