我们可以通过 for 循环 和 format 的配合来进行动态输出
代码:
import time #导入 time 模块
text = ['a','b','c'] #动态输出的文字(可根据需求修改)
for i in text: # for 循环
print('\r动态输出:{}'.format(i),end = '')
#大括号内为动态变化的内容,内容以列表形式填写在 format 里
time.sleep(1) #输出间隙
通过动态输出和获取时间的结合,我们也可以进行动态报时
代码示例 :
#导入模块
import time as tm
import json as js
import requests as re
import datetime as dt
import calendar as cl
def data(): #获取时间
year = int(tm.strftime("%Y", tm.localtime()))
month = int(tm.strftime("%m", tm.localtime()))
mint = int(tm.strftime("%M", tm.localtime()))
sec = int(tm.strftime("%S", tm.localtime()))
hour = int(tm.strftime("%H", tm.localtime()))
f = int(dt.datetime.now().strftime('%f'))/1000
hm =str(int(float('%.32f' % f)//10))
hr = int(float('%.32f' % f)//10)
time = tm.strftime("%H:%M:%S", tm.localtime())
date = tm.strftime("%d", tm.localtime())
rb=re.get('http://wthrcdn.etouch.cn/weather_mini?city=上海')
data = js.loads(rb.text)
lis = data['data']['forecast'][0]
weather = lis['type']
high = lis['high'].replace('高温 ','')
low = lis['low'].replace('低温 ','')
fx = lis['fengxiang'].replace('风','')
calendar = cl.month(year,month)
data_td = {'年份':year,'月':month,'日':date,'时':hour,'分':mint,'秒':sec,'毫秒':hr,'天气':weather,'最高气温':high,'最低气温':low,'风向':fx}
return data_td
#动态输出
while True:
x = data()
print('\r' , x['年份'],'/',x['月'],'/',x['日'],'---',x['时'],':',x['分'],':',x['秒'],':',x['毫秒'],end = '')
tm.sleep(0.1)
*注:有些库如未安装,请使用 pip install + 库名 进行安装
我们可以用 pyautogui 库 进行动态鼠标坐标输出
代码示例:
#导入库
from pyautogui import *
from time import *
#动态输出
while True:
print('\r鼠标坐标为:x {} ,y {}'.format(position()[0],position()[1]),end = ' ')
sleep(0.001)