PYTHON 获取淘宝服务器时间 显示在tkinter的UI
生活随笔
收集整理的這篇文章主要介紹了
PYTHON 获取淘宝服务器时间 显示在tkinter的UI
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
代碼
#!/usr/bin/python # -*- coding: UTF-8 -*-import tkinter import http.client import timedef get_webservertime(host):conn = http.client.HTTPConnection(host)conn.request("GET", "/")r = conn.getresponse()ts = r.getheader('date') # 獲取http頭date部分# 將GMT時(shí)間轉(zhuǎn)換成北京時(shí)間ltime = time.strptime(ts[5:25], "%d %b %Y %H:%M:%S")ttime = time.localtime(time.mktime(ltime) + 8 * 60 * 60)dat = "%u-%02u-%02u" % (ttime.tm_year, ttime.tm_mon, ttime.tm_mday)tm = "%02u:%02u:%02u" % (ttime.tm_hour, ttime.tm_min, ttime.tm_sec)return tmdef tick():global time1# 獲取時(shí)間time2 = get_webservertime('www.taobao.com')# 如果時(shí)間發(fā)生變化,代碼自動(dòng)更新顯示的系統(tǒng)時(shí)間if time2 != time1:time1 = time2clock.config(text=time2)# calls itself every 200 milliseconds# to update the time display as needed# could use >200 ms, but display gets jerkyclock.after(200, tick)win = tkinter.Tk() win.title("獲取淘寶服務(wù)器時(shí)間") time1 = '' clock = tkinter.Label(win, font=('times', 100, 'bold'), bg='green') clock.grid(row=0, column=1) tick() win.mainloop()效果
總結(jié)
以上是生活随笔為你收集整理的PYTHON 获取淘宝服务器时间 显示在tkinter的UI的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: [html] HTML全局属性(glob
- 下一篇: [vue] 你有写过自定义指令吗?自定义