質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
PyAutoGUI

PyAutoGUIは、Windows、Mac OS、Linuxに対応した、Python用のGUI自動化ライブラリです。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

解決済

1回答

890閲覧

#Python#pyautogui,moveTo()

napnpan

総合スコア10

PyAutoGUI

PyAutoGUIは、Windows、Mac OS、Linuxに対応した、Python用のGUI自動化ライブラリです。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2022/09/04 12:26

前提

Python3.8でpyautoguiというライブラリを用いて、カーソルを移動させる練習をしています。
x軸だけカーソルの座標を移動させるを実装中に以下のエラーメッセージが発生しました。
どなたか詳しい方がいらしたら、教えていただきたいです。

実現したいこと

pag.moveTo(500,None,3.5)
エラーがでるので、Noneを書き換えたい

発生している問題・エラーメッセージ

--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-17-a10d7d70ed55> in <module> 11 12 # 3.5 秒かけてX のみ移動 ---> 13 pag.moveTo(500,None,3.5) 14 print("position{0}". format( pag. position())) 15 ~\Anaconda3\lib\site-packages\pyautogui\__init__.py in wrapper(*args, **kwargs) 596 def wrapper(*args, **kwargs): 597 failSafeCheck() --> 598 returnVal = wrappedFunction(*args, **kwargs) 599 _handlePause(kwargs.get("_pause", True)) 600 return returnVal ~\Anaconda3\lib\site-packages\pyautogui\__init__.py in moveTo(x, y, duration, tween, logScreenshot, _pause) 1278 None 1279 """ -> 1280 x, y = _normalizeXYArgs(x, y) 1281 1282 _logScreenshot(logScreenshot, "moveTo", "%s,%s" % (x, y), folder=".") ~\Anaconda3\lib\site-packages\pyautogui\__init__.py in _normalizeXYArgs(firstArg, secondArg) 699 ) 700 else: --> 701 return Point(int(firstArg), int(secondArg)) # firstArg and secondArg are just x and y number values 702 703 TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

該当のソースコード

Python

1# -* - coding: utf-8 -*- 2import pyautogui as pag #GUI操作毎のポーズ秒数 3 4# 3.5 秒かけてX のみ移動 5pag.moveTo(500,None,3.5) 6print("position{0}". format( pag. position()))

試したこと

pag.moveToの引数にはNoneがデェフォルトになっているので、何も書かずに入力してもエラーがでました。

Signature:
pag.moveTo(
x=None,
y=None,
duration=0.0,
tween=<function linear at 0x00000241C2B11798>,
logScreenshot=False,
_pause=True,
)
Docstring:
Moves the mouse cursor to a point on the screen.

The x and y parameters detail where the mouse event happens. If None, the
current mouse position is used. If a float value, it is rounded down. If
outside the boundaries of the screen, the event happens at edge of the
screen.

Args:
x (int, float, None, tuple, optional): The x position on the screen where the
click happens. None by default. If tuple, this is used for x and y.
If x is a str, it's considered a filename of an image to find on
the screen with locateOnScreen() and click the center of.
y (int, float, None, optional): The y position on the screen where the
click happens. None by default.
duration (float, optional): The amount of time it takes to move the mouse
cursor to the xy coordinates. If 0, then the mouse cursor is moved
instantaneously. 0.0 by default.
tween (func, optional): The tweening function used if the duration is not
0. A linear tween is used by default.

Returns:
None
File: c:\users\sd19080\anaconda3\lib\site-packages\pyautogui_init_.py
Type: function

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

jbpb0

2022/09/05 02:30

「pag.moveTo()」よりも先に「pag.position()」を実行してマウスの現在位置を取得しておいて、取得したy座標を「pag.moveTo()」のy座標に指定すればいいのでは?? あるいは、「pag.moveTo()」ではなくて「pag.moveRel()」を使うとか https://www.stjun.com/entry/2020/05/07/134458
guest

回答1

0

自己解決

ありがとうございました。解決しました。

投稿2022/09/07 15:13

napnpan

総合スコア10

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問