Python使用tkinter實(shí)現(xiàn)小時鐘效果
本文實(shí)例為大家分享了Python使用tkinter實(shí)現(xiàn)小時鐘效果的具體代碼,供大家參考,具體內(nèi)容如下
自己又調(diào)試了一下,分享一下
# coding:utf-8from tkinter import *import math,timedef points(): for i in range(1,13): x = 200 + 130*math.sin(2*math.pi*i/12) y = 200 - 130*math.cos(2*math.pi*i/12) canvas.create_text(x,y,text=i)def createline(radius,line_width,rad): global List global i List = [] x = 200+radius*math.sin(rad) y = 200-radius*math.cos(rad) i=canvas.create_line(200,200,x,y,width=line_width) List.append(i)root = Tk()root.resizable(0,0)canvas = Canvas(root,width=400,height=500,bd=0,highlightthickness=0)canvas.pack()canvas.create_oval(50,50,350,350)points()while 1: tm=time.localtime() t=time.asctime(tm) t_hour=0 if tm.tm_hour<=12: t_hour=tm_hour else: t_hour=tm.tm_hour-12 rad1=2*math.pi*(t_hour+tm.tm_min/60)/12 rad2=2*math.pi*(tm.tm_min+tm.tm_sec/60)/60 rad3=2*math.pi*tm.tm_sec/60 createline(50,6,rad1,) createline(90,3,rad2) createline(120,1,rad3) l=canvas.create_text(170,450,text=t) root.update() time.sleep(1) for item in List: canvas.delete(item) canvas.delete(l)root.update()mainloop()
效果
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)2. 將properties文件的配置設(shè)置為整個Web應(yīng)用的全局變量實(shí)現(xiàn)方法3. 在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法4. 得到XML文檔大小的方法5. ASP.NET Core實(shí)現(xiàn)中間件的幾種方式6. 如何在jsp界面中插入圖片7. jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫的方法8. 利用CSS3新特性創(chuàng)建透明邊框三角9. XML入門的常見問題(二)10. ASP常用日期格式化函數(shù) FormatDate()
