import tkinter as tk
import ping3
def update_label():
# 更新Label的内容
# label.config(text="新的内容")
response_time = ping3.ping("www.baidu.com")
label.config(text="Ping baidu success time =" + str(round(response_time * 1000, 2)) + "ms")
# 通过after方法定时调用update_label函数,实现循环更新
label.after(1000, update_label)
# 创建Tkinter窗口
window = tk.Tk()
window.title("Label更新示例")
# 创建Label
label = tk.Label(window, text="初始内容")
label.pack()
# 调用update_label函数来更新Label的内容
update_label()
# 运行Tkinter窗口的主循环
window.mainloop()
用python ping百度并返回延时毫秒
最新推荐文章于 2024-02-12 12:53:53 发布