首页 > 解决方案 > 不打印减号

问题描述

我写的

pyautogui.typewrite(to_type)

为自动化键盘和鼠标编写脚本。to_type = -0.2,它只写 0.2。我有英文键盘。它不加减号为

pyautogui.typewrite(-0.2)

也是。你知道问题出在哪里吗?谢谢

代码

import pyautogui 
import time 
for i in range(1, 3): 
    pyautogui.click(509, 679) # move to field 
    pyautogui.typewrite(['backspace', 'backspace', 'backspace', 'backspace', 'backspace', 'backspace', 'backspace', 'backspace']) 
    value = -0.5 + (i - 1) * 0.3 # computation numbers that will be write in field 
    to_type = "%f" % value 
    print(to_type) 
    #pyautogui.press('-')
    pyautogui.typewrite(to_type) # writing previous number 
    time.sleep(2) 
    pyautogui.typewrite(['enter']) # enter the input of number 
    pyautogui.PAUSE = 0.5
    pyautogui.click(169, 681) # plot
    pyautogui.PAUSE = 0.5
    pyautogui.click(330, 685) # save 
    pyautogui.click(448, 174) # file name 
    to_type = "data{}".format(i) 
    print(to_type) 
    pyautogui.typewrite(to_type) # writing name of file 
    pyautogui.click(978, 664) # save file
    pyautogui.PAUSE = 0.5

标签: pythonpython-3.xautomation

解决方案


typewrite 接受一个字符串,但你传递了一个浮点数。尝试这个:

pyautogui.typewrite("-0.2")

推荐阅读