import
math
import
pygame
import
sys
import
tkinter
from
datetime
import
datetime
tk
=
tkinter.Tk()
width
=
tk.winfo_screenwidth()
height
=
tk.winfo_screenheight()
tk.quit()
def
print_text(font, x, y, text, angle, color
=
(
255
,
255
,
255
)):
img_text
=
font.render(text,
True
, color)
img_text
=
pygame.transform.rotate(img_text, angle)
screen.blit(img_text, (x, y))
def
cycle_text(cirText, bins, today_xx, cirRadius, font, color
=
(
255
,
255
,
255
)):
for
i
in
range
(
1
,
len
(cirText)
+
1
):
c_angle
=
math.radians(
360
/
bins)
*
(today_xx
-
i)
t_angle
=
0
-
(
360
/
bins)
*
(today_xx
-
i)
add_x
=
math.cos(c_angle)
*
cirRadius
add_y
=
math.sin(c_angle)
*
cirRadius
print_text(font, pos_x
+
add_x, pos_y
+
add_y,
str
(cirText[i
-
1
]), angle
=
t_angle, color
=
color)
pygame.init()
screen
=
pygame.display.set_mode((width, height), pygame.FULLSCREEN)
pygame.display.set_caption(
"Python Clock"
)
font1
=
pygame.font.Font(
"C:/Windows/Fonts/msyh.ttc"
,
16
)
font2
=
pygame.font.Font(
"C:/Windows/Fonts/msyh.ttc"
,
25
)
font3
=
pygame.font.Font(
"C:/Windows/Fonts/msyh.ttc"
,
22
)
pos_x
=
width
/
2
pos_y
=
(height
/
2
)
-
30
r
=
395
secondsText
=
[
"零壹秒"
,
"零贰秒"
,
"零叁秒"
,
"零肆秒"
,
"零伍秒"
,
"零陆秒"
,
"零柒秒"
,
"零捌秒"
,
"零玖秒"
,
"壹拾秒"
,
"拾壹秒"
,
"拾贰秒"
,
"拾叁秒"
,
"拾肆秒"
,
"拾伍秒"
,
"拾陆秒"
,
"拾柒秒"
,
"拾捌秒"
,
"拾玖秒"
,
"贰拾秒"
,
"贰拾壹秒"
,
"贰拾贰秒"
,
"贰拾叁秒"
,
"贰拾肆秒"
,
"贰拾伍秒"
,
"贰拾陆秒"
,
"贰拾柒秒"
,
"贰拾捌秒"
,
"贰拾玖秒"
,
"叁拾秒"
,
"叁拾壹秒"
,
"叁拾贰秒"
,
"叁拾叁秒"
,
"叁拾肆秒"
,
"叁拾伍秒"
,
"叁拾陆秒"
,
"叁拾柒秒"
,
"叁拾捌秒"
,
"叁拾玖秒"
,
"肆拾秒"
,
"肆拾壹秒"
,
"肆拾贰秒"
,
"肆拾叁秒"
,
"肆拾肆秒"
,
"肆拾伍秒"
,
"肆拾陆秒"
,
"肆拾柒秒"
,
"肆拾捌秒"
,
"肆拾玖秒"
,
"伍拾秒"
,
"伍拾壹秒"
,
"伍拾贰秒"
,
"伍拾叁秒"
,
"伍拾肆秒"
,
"伍拾伍秒"
,
"伍拾陆秒"
,
"伍拾柒秒"
,
"伍拾捌秒"
,
"伍拾玖秒"
,
"零 秒"
]
minuteText
=
[
"零壹分"
,
"零贰分"
,
"零叁分"
,
"零肆分"
,
"零伍分"
,
"零陆分"
,
"零柒分"
,
"零捌分"
,
"零玖分"
,
"壹拾分"
,
"拾壹分"
,
"拾贰分"
,
"拾叁分"
,
"拾肆分"
,
"拾伍分"
,
"拾陆分"
,
"拾柒分"
,
"拾捌分"
,
"拾玖分"
,
"贰拾分"
,
"贰拾壹分"
,
"贰拾贰分"
,
"贰拾叁分"
,
"贰拾肆分"
,
"贰拾伍分"
,
"贰拾陆分"
,
"贰拾柒分"
,
"贰拾捌分"
,
"贰拾玖分"
,
"叁拾分"
,
"叁拾壹分"
,
"叁拾贰分"
,
"叁拾叁分"
,
"叁拾肆分"
,
"叁拾伍分"
,
"叁拾陆分"
,
"叁拾柒分"
,
"叁拾捌分"
,
"叁拾玖分"
,
"肆拾分"
,
"肆拾壹分"
,
"肆拾贰分"
,
"肆拾叁分"
,
"肆拾肆分"
,
"肆拾伍分"
,
"肆拾陆分"
,
"肆拾柒分"
,
"肆拾捌分"
,
"肆拾玖分"
,
"伍拾分"
,
"伍拾壹分"
,
"伍拾贰分"
,
"伍拾叁分"
,
"伍拾肆分"
,
"伍拾伍分"
,
"伍拾陆分"
,
"伍拾柒分"
,
"伍拾捌分"
,
"伍拾玖分"
,
"零 分"
]
hourText
=
[
"零壹点"
,
"零两点"
,
"零叁点"
,
"零肆点"
,
"零伍点"
,
"零陆点"
,
"零柒点"
,
"零捌点"
,
"零玖点"
,
"壹拾点"
,
"拾壹点"
,
"拾贰点"
,
"拾叁点"
,
"拾肆点"
,
"拾伍点"
,
"拾陆点"
,
"拾柒点"
,
"拾捌点"
,
"拾玖点"
,
"贰拾点"
,
"贰拾壹点"
,
"贰拾贰点"
,
"贰拾叁点"
,
"零 点"
]
weekText
=
[
"星期壹"
,
"星期贰"
,
"星期叁"
,
"星期肆"
,
"星期伍"
,
"星期陆"
,
"星期日"
]
dayText
=
[
"零壹日"
,
"零贰日"
,
"零叁日"
,
"零肆日"
,
"零伍日"
,
"零陆日"
,
"零柒日"
,
"零捌日"
,
"零玖日"
,
"壹拾日"
,
"拾壹日"
,
"拾贰日"
,
"拾叁日"
,
"拾肆日"
,
"拾伍日"
,
"拾陆日"
,
"拾柒日"
,
"拾捌日"
,
"拾玖日"
,
"贰拾日"
,
"贰拾壹日"
,
"贰拾贰日"
,
"贰拾叁日"
,
"贰拾肆日"
,
"贰拾伍日"
,
"贰拾陆日"
,
"贰拾柒日"
,
"贰拾捌日"
,
"贰拾玖日"
,
"叁拾日"
,
"叁拾壹日"
]
monthText
=
[
"零壹月"
,
"零贰月"
,
"零叁月"
,
"零肆月"
,
"零伍月"
,
"零陆月"
,
"零柒月"
,
"零捌月"
,
"零玖月"
,
"拾 月"
,
"拾壹月"
,
"拾贰月"
]
yearText
=
list
(
range
(
1
,
3000
))
yearText[
2020
:
2051
]
=
[
"贰零贰零年"
,
"贰零贰壹年"
,
"贰零贰贰年"
,
"贰零贰叁年"
,
"贰零贰肆年"
,
"贰零贰伍年"
,
"贰零贰陆年"
,
"贰零贰柒年"
,
"贰零贰捌年"
,
"贰零贰玖年"
,
"贰零叁零年"
,
"贰零叁壹年"
,
"贰零叁贰年"
,
"贰零叁叁年"
,
"贰零叁肆年"
,
"贰零叁伍年"
,
"贰零叁陆年"
,
"贰零叁柒年"
,
"贰零叁捌年"
,
"贰零叁玖年"
,
"贰零肆零年"
,
"贰零肆壹年"
,
"贰零肆贰年"
,
"贰零肆叁年"
,
"贰零肆肆年"
,
"贰零肆伍年"
,
"贰零肆陆年"
,
"贰零肆柒年"
,
"贰零肆捌年"
,
"贰零肆玖年"
,
"贰零伍零年"
]
while
True
:
for
event
in
pygame.event.get():
if
event.
type
=
=
pygame.QUIT:
sys.exit()
keys
=
pygame.key.get_pressed()
if
keys[pygame.K_ESCAPE]:
sys.exit()
screen.fill(color
=
(
0
,
115
,
120
))
pygame.draw.line(screen, color
=
"red"
, start_pos
=
(pos_x
+
15
, pos_y
+
25
), end_pos
=
(pos_x
+
r
+
60
, pos_y
+
25
), width
=
2
)
year
=
datetime.today().year
print_text(font2, pos_x
-
35
, pos_y
-
15
, text
=
yearText[year], angle
=
0
, color
=
"red"
)
months
=
datetime.today().month
cycle_text(cirText
=
monthText, bins
=
12
, today_xx
=
months, cirRadius
=
r
-
290
, font
=
font1, color
=
"white"
)
days
=
datetime.today().day
if
months
in
[
1
,
3
,
5
,
7
,
8
,
10
,
12
]:
cycle_text(cirText
=
dayText, bins
=
31
, today_xx
=
days, cirRadius
=
r
-
225
, font
=
font1, color
=
"white"
)
elif
months
in
[
4
,
6
,
9
,
11
]:
cycle_text(cirText
=
dayText[
0
:
-
1
], bins
=
30
, today_xx
=
days, cirRadius
=
r
-
225
, font
=
font1, color
=
"white"
)
elif
months
=
=
2
:
if
(year
%
4
=
=
0
and
year
%
100
!
=
0
)
or
year
%
400
=
=
0
:
cycle_text(cirText
=
dayText[
0
:
-
2
], bins
=
29
, today_xx
=
days, cirRadius
=
r
-
225
, font
=
font1, color
=
"white"
)
else
:
cycle_text(cirText
=
dayText[
0
:
-
3
], bins
=
28
, today_xx
=
days, cirRadius
=
r
-
225
, font
=
font1, color
=
"white"
)
weeks
=
datetime.today().isoweekday()
print_text(font3, pos_x
-
8
, pos_y
+
30
, text
=
weekText[weeks
-
1
], angle
=
0
, color
=
"blue"
)
hours
=
datetime.today().hour
%
24
cycle_text(cirText
=
hourText, bins
=
24
, today_xx
=
hours, cirRadius
=
r
-
150
, font
=
font1, color
=
"white"
)
minutes
=
datetime.today().minute
cycle_text(cirText
=
minuteText, bins
=
60
, today_xx
=
minutes, cirRadius
=
r
-
75
, font
=
font1, color
=
"white"
)
seconds
=
datetime.today().second
cycle_text(cirText
=
secondsText, bins
=
60
, today_xx
=
seconds, cirRadius
=
r, font
=
font1, color
=
"white"
)
pygame.display.update()