想要掌握这个pyautogui命令 [英] Want to get a grip of this pyautogui command

查看:86
本文介绍了想要掌握这个pyautogui命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我几乎只复制了这段代码,它获得了光标的 x y 位置,并且'我想问一下每行命令是什么这样我就可以掌握它.

Well, I pretty much just copied this code that gets the x and y position of the cursor, and 'I'd like to ask what each line of command does so I can get a grip of it.

提前谢谢!

print('Type Ctrl-C to stop the program')


try:
    while True:
        x, y = pg.position() 
        coordinates = 'X: ' + str(x).ljust(4) + ' Y: ' + str(y).ljust(4)


        print(coordinates, end='')
        print('\b' * len(coordinates), end='', flush = True)

except KeyboardInterrupt():
    print('\n See you next time!')

推荐答案

您已经定义了while循环,该循环永远不会结束,因为 True 是普遍真理.

You have defined a while loop which will never end as True is universal truth.

之后,您使用了 pg.position()来获取实时光标位置,该位置将为您提供屏幕上光标在x和y中定义的两个元组中的x和y坐标..您可以使用 pg.size()

After that you have used pg.position() to get the live cursor position which will give you the x and and y coordinate of the cursor on the screen in two tuples defined here x and y. You can get your screen size with pg.size()

然后,您要定义一个名为 coordinates 的变量,您将在其中使用 ljust()方法,该方法返回给定最小宽度内的左对齐字符串. str.ljust(width [,fillchar])如果定义了fillchar,它还将用定义的字符填充剩余空间.

Then you are defining a variable named coordinates where you are using ljust() method that returns the left-justified string within the given minimum width. str.ljust(width[, fillchar]) If fillchar is defined, it also fills the remaining space with the defined character.

在下一行中,您已经打印了坐标,并再次使用 flush()方法打印了坐标的长度,该方法的唯一作用是刷新内部缓冲区. \ b 用于退格一个字符.

In next line you have printed the coordinates and again printing length of coordinates with flush() method whose only work is to flush the internal buffer. \b is used to backspace one character before it.

最后,您使用的是 KeyboardInterrupt(),当您尝试通过在命令行中按ctrl + c或ctrl + z来停止正在运行的程序时会出现此错误.这是一个摘要,但是为了掌握,我建议您阅读整个文档.

And in the last you are using KeyboardInterrupt() which is raised when you try to stop a running program by pressing ctrl+c or ctrl+z in a command line . This is a summary but to get grip I recommend to see the whole documentation.

希望有帮助!

这篇关于想要掌握这个pyautogui命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆