I'm trying to click into a program window using pyautogui.
When clicking in the program window, on a button I wish to press, a loading icon appears next to the mouse cursor as if it is thinking, and it never actually clicks. It does, however, move to the cursor location that I provide.
Here's the code
import pyautogui
pyautogui.doubleClick(x=300, y=300)
I opened Excel to see if it will click into that, and it does, but only if I run the code as:
import pyautogui
pyautogui.doubleClick(x=300, y=300)
pyautogui.doubleClick(x=300, y=300)
What the heck do I do?
If the application in running as administrator and pyautogui script is not running as administrators, then control will not work. pyautogui script should also run as administrator to control it
Try giving the interval argument
pyautogui.doubleClick(x=300, y=300, interval=0.25)
Related
Python: 3.10.6,
os: MacOS 12.6,
Software: VS code
I want to confirm before activating the mouse_click()with pyautogui's message box (.alert or .confirm).
Running the script the message box opens, and if I do nothing its okey. But once I click in the message box, a button or anywhere in the message box window, the 'spinning wheel' appears. The application window crashes and needs to 'Force quit'.
Its the same with every message box.
import pyautogui
import time
def mouse_click():
while True:
time.sleep(1)
pyautogui.click()
def main():
pyautogui.confirm('Shall I proceed?')
mouse_click()
main()
quit()
What might be the issue?
I believe your issue may stem from being in a while loop:
taking it out of the loop seems to fix things. The confirm box also returns the value of the button clicked so I implemented that.
import pyautogui
import time
x = pyautogui.confirm('Shall I proceed?', title='Are you sure?', buttons=['Ok', 'Cancel'])
if x == 'Ok':
time.sleep(1)
pyautogui.click()
else:
quit()
Though for some reason the box doesn't close until after the click event.
In any event you can work around this by making pyautogui move your mouse and click elsewhere.
the solution would be the use of 'threading'. As having an active GUI and a task running in a loop causes the GUI to freeze, looks to have crashed, until the loop has ended.
some info about threading can be found here Python threading and PySimpleGUI
I've moved over to PySimpleGUI and used threading. Explanation and demo code:
https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Multithreaded_Multiple_Threads.py
I have some Python experience and wish to learn about GUI development using tkinter.
I can create a simple widget, but when I try to close the window, things "hang" and nothing happens. Only by restarting the Python kernel can I get the window to close.
I'm running Python 3.7 using Spyder and, based upon some simple examples I've found in other forums tried the following:
import tkinter
root = tkinter.Tk()
root.title("Hello!")
simple_label = tkinter.Label(root, text="Easy, right?")
closing_button = tkinter.Button(root, text="Close window",
command=root.destroy)
simple_label.pack()
closing_button.pack()
root.mainloop()
As I mention above, the window does not close when I click my mouse on the Close Window button. I just get the "swirly" indicator on my Mac indicating the program is not responding. However, I am able to perform calculations in the Spyder console.
The code works fine, but what you should do is open the program in the Python IDLE that comes when you download Python. When you run the program it should open up the Python Launcher, which allows you to interact your your GUI (And it will let you close click the close button) I am using a Mac and everything works fine.
I was analyzing your case and we BOTH did something we didn't notice after.
When you use the "root.destroy" command, you should add parenthesis after.. Had the same thing happening to me
Added root.destroy ( ) and worked flawlessly. <-- Use it without SPACES
Hope it helps someone in the future!
I'm trying to get PyWinAuto to click a button as soon as it's enabled. Here's what I currently have:
while running:
try:
app = pywinauto.Application().connect(title='Microsoft Outlook', class_name="#32770")['Microsoft Outlook']
app.Allow.Wait('ready', retry_interval=0.1)
app.Allow.Click()
print('Clicked')
except (pywinauto.findbestmatch.MatchError, pywinauto.findwindows.ElementNotFoundError):
time.sleep(0.1)
pass
This works just fine if I start it running after the button is active, clicking and printing 'Clicked' as expected. If I run it before the button is active, it waits for it as expected and then seems to try and click it - Printing 'clicked' repeatedly until I click either mouse button or press enter. If I take the click() out and get it to just return app.Allow then the result is as expected regardless of when I load the script, so it does seem to be click() that's the hangup.
The behaviour is the same regardless of where I click or which window I have active - It'll work if I click anywhere or anything, but it won't do anything at all until I do... Which defeats the object of the automation, really!
Any ideas?
Thanks!
First you have to run the script as Administrator if you use .connect(...). I've already added warning about that and error in the .click() method when target process has higher privileges. See pull request #499. It will be included into coming pywinauto==0.6.5.
There is one more method: .click_input() moves mouse cursor and performs real click. While .click() just sends WM_CLICK window message (might be useful for minimized or non-active window).
P.S. By the way, for Outlook I'd recommend using Application(backend="uia") and you'll have no Win32 API specific problems. See Getting Started Guide about backends difference.
When trying to close my tkinter window using the red 'x' button (top left) the window doesn't close and python crashes(colour wheel).
(note this is across all of my Tkinter apps, not just the one shown)
Here is an image of my code:
Here is the crashed white box, neither "quit" or red "x" works. It doesn't show up in the screenshot but the spinning colour wheel is visible whenever I hover over my window. I have to force quit due to "Python not responding".
Got me thinking when I run python in the shell there's an error message: TK Tcl. Maybe unstable.
I suggest to try master.destroy instead of frame.quit for the callback of the Quit button, and give us feedback whether it changes anything
I am currently trying to make a physics simulation using VPython on my laptop. I want to make a GUI so that when the client presses the run simulation button, it opens chrome and the simulation runs, after taking the user's input from entry boxes. However, when I run the source code, chrome automatically opens and I want it to open only when the user presses the run simulation button. I tried using the lambda method to bind the function to the button, but it isn't working. Here is a very simplified version of what I am trying to do:
import tkinter as tk
from vpython import *
### Simulation ###
def run_simulation(r):
sphere(radius=r)
### GUI ###
root = tk.Tk()
text_variable = tk.StringVar()
entry = tk.Entry(root, textvariable=text_variable, width=10)
entry.pack()
button = tk.Button(root, text='Run Simulation', command= lambda: run_simulation(eval(text_variable.get())))
button.pack()
root.mainloop()
In short, if you run this code, it will open chrome automatically (even though I used lambda), but I only want it to do so if the button is clicked. Thanks in advance.
Here are a bunch of vpython demo programs that you can run in a browser using glowscript vpython
http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/
Just click run beside the image and it runs the simulation.
These same vpthon Demo programs are also found on github here.
https://github.com/BruceSherwood/vpython-jupyter/tree/master/Demos_no_notebook
you can run the programs from the Windows Command prompt if you have python 3.6 installed on your machine. Just type
python BinaryStar.py
and it will open a web browser and run the BinaryStar vpython demo program. You can do the same for the other demo programs in the above directory on github.
Maybe you can get your button to run the command "python myVpythonProgram.py" to run the vpython program you want to run in a browser.