直播視頻網(wǎng)站源碼,實現(xiàn)靜態(tài)時鐘的相關(guān)代碼
stillclock.py:
from tkinter import *
import math
from datetime import datetimeclass
stillClock(Canvas
):def __init__
(self, container
):super().__init__
(container
)self.
setCurrentTime()def
getHour(self
):return self.__hourdef
setHour(self, hour
):self.__hour = hourdef
getMinute(self
):return self.__minutedef
setMinute(self, minute
):self.__minute = minutedef
getSecond(self
):return self.__seconddef
setSecond(self, second
):self.__second = seconddef
setCurrentTime(self
):d = datetime.
now()self.__hour = d.hourself.__minute = d.minuteself.__second = d.secondself.
delete("clock")self.
drawClock()def
drawClock(self
):self.
delete("clock")width =
float(self[
"width"]
)height =
float(self[
"height"]
)radius =
min(width, height
) / 2.4secondHandLength = radius * 0.8minuteHandLength = radius * 0.65hourHandLength = radius * 0.5center_w = width / 2center_h = height / 2self.create_
oval(center_w - radius, center_h - radius, center_w + radius, center_h + radius, tags=
"clock")self.create_
text(center_w - radius + 5, center_h, text=
"9", tags=
"clock")self.create_
text(center_w + radius - 5, center_h, text=
"3", tags=
"clock")self.create_
text(center_w, center_h + 5 - radius, text=
"12", tags=
"clock")self.create_
text(center_w, center_h + radius - 5, text=
"6", tags=
"clock")xCenter = center_wyCenter = center_hsecond = self.__secondxSecond = xCenter + secondHandLength * math.
sin(second *
(2 * math.pi / 60
))ySecond = yCenter - secondHandLength * math.
cos(second *
(2 * math.pi / 60
))self.create_
line(xCenter, yCenter, xSecond, ySecond, fill=
"red", tags=
"clock")minute = self.__minutexMinute = xCenter + minuteHandLength * math.
sin(minute *
(2 * math.pi / 60
))yMinute = yCenter - minuteHandLength * math.
cos(minute *
(2 * math.pi / 60
))self.create_
line(xCenter, yCenter, xMinute, yMinute, fill=
"blue", tags=
"clock")hour = self.__hour % 12xHour = xCenter + hourHandLength * math.
sin((hour+minute/60
) *
(2 * math.pi / 12
))yHour = yCenter - hourHandLength * math.
cos((hour+minute/60
)*
(2 * math.pi / 12
))self.create_
line(xCenter, yCenter, xHour, yHour, fill=
"green", tags=
"clock")timestr =
str(hour
) +
":" +
str(minute
) +
":" +
str(second
)self.create_
text(xCenter, yCenter + radius + 10, text=timestr, tags=
"clock")
測試:
from tkinter import *
from stillclock import stillClockclass
stillclockTest:def __init__
(self
):window =
Tk()window.
title("change clock time")self.clock =
stillClock(window
)self.clock.
pack()frame =
Frame(window
)frame.
pack()Label(frame, text=
"Hour").
pack(side=LEFT
)self.hour =
IntVar()self.hour.
set(self.clock.
getHour())Entry(frame, textvariable=self.hour,width=2
).
pack(side=LEFT
)Label(frame, text=
"Minute").
pack(side=LEFT
)self.minute =
IntVar()self.minute.
set(self.clock.
getMinute())Entry(frame, textvariable=self.minute,width=2
).
pack(side=LEFT
)Label(frame, text=
"Second").
pack(side=LEFT
)self.second =
IntVar()self.second.
set(self.clock.
getSecond())Entry(frame, textvariable=self.second,width=2
).
pack(side=LEFT
)Button(frame, text=
"Set New Time", command=self.setNewTime
).
pack(side=LEFT
)window.
mainloop()def
setNewTime(self
):self.clock.
setHour(self.hour.
get())self.clock.
setMinute(self.minute.
get())self.clock.
setSecond(self.second.
get())self.clock.
drawClock()stillclockTest()
以上就是關(guān)于直播視頻網(wǎng)站源碼,實現(xiàn)靜態(tài)時鐘的相關(guān)代碼,更多內(nèi)容歡迎關(guān)注之后的文章
本文轉(zhuǎn)載自網(wǎng)絡(luò),轉(zhuǎn)載僅為分享干貨知識,如有侵權(quán)歡迎聯(lián)系云豹科技進行刪除處理
總結(jié)
以上是生活随笔為你收集整理的直播视频网站源码,静态时钟的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。