Skip to content

Commit 53d1ed2

Browse files
[投稿] 添加脚本: 汇率转换器 — by 今晚打老虎
1 parent 6f03959 commit 53d1ed2

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# 欢迎使用 PythonIDE!如果觉得好用,请给个好评哦~
2+
# -*- coding: utf-8 -*-
3+
"""汇率转换器 — major currencies with flags and trend arrows."""
4+
5+
from widget import Widget, family, SMALL, MEDIUM, LARGE
6+
import time
7+
8+
currencies = [
9+
("🇺🇸", "USD", 1.0000, "up"),
10+
("🇪🇺", "EUR", 0.9182, "down"),
11+
("🇯🇵", "JPY", 149.85, "up"),
12+
("🇬🇧", "GBP", 0.7923, "down"),
13+
("🇨🇳", "CNY", 7.2450, "up"),
14+
]
15+
16+
now = time.strftime("%H:%M")
17+
18+
bg = ("#F8FAFC", "#0F172A")
19+
card_bg = ("#F1F5F9", "#1E293B")
20+
txt_main = ("#0F172A", "#F8FAFC")
21+
txt_sub = ("#64748B", "#94A3B8")
22+
up_clr = ("#10B981", "#34D399")
23+
down_clr = ("#EF4444", "#F87171")
24+
accent = "#3B82F6"
25+
26+
w = Widget(background=bg, padding=14)
27+
28+
if family == SMALL:
29+
with w.vstack(spacing=0, align="center"):
30+
w.spacer()
31+
w.icon("dollarsign.circle.fill", size=18, color=accent)
32+
w.spacer(6)
33+
w.text("1 USD", size=22, weight="bold", design="rounded", color=txt_main)
34+
w.spacer(4)
35+
with w.hstack(spacing=4):
36+
w.text("🇺🇸", size=14)
37+
w.text("USD", size=12, weight="semibold", color=txt_main)
38+
w.spacer()
39+
w.text("基准", size=10, color=txt_sub)
40+
w.spacer()
41+
with w.hstack(spacing=6):
42+
clr = up_clr
43+
arrow = "arrow.up.right"
44+
w.icon(arrow, size=8, color=clr)
45+
w.text("EUR 0.92", size=11, weight="medium", color=clr)
46+
w.spacer()
47+
clr = down_clr
48+
arrow = "arrow.down.right"
49+
w.icon(arrow, size=8, color=clr)
50+
w.text("JPY 149.9", size=11, weight="medium", color=clr)
51+
w.spacer()
52+
53+
elif family == MEDIUM:
54+
with w.vstack(spacing=0):
55+
with w.hstack(spacing=6):
56+
w.icon("dollarsign.circle.fill", size=14, color=accent)
57+
w.text("汇率", size=14, weight="semibold", color=txt_main)
58+
w.spacer()
59+
w.text(f"更新 {now}", size=11, color=txt_sub)
60+
w.spacer()
61+
with w.hstack(spacing=0):
62+
for flag, code, rate, trend in currencies[:4]:
63+
with w.vstack(spacing=2, align="center"):
64+
clr = up_clr if trend == "up" else down_clr
65+
arrow = "arrow.up.right" if trend == "up" else "arrow.down.right"
66+
w.text(flag, size=16)
67+
w.text(code, size=11, weight="semibold", color=txt_main)
68+
with w.hstack(spacing=2):
69+
w.icon(arrow, size=8, color=clr)
70+
w.text(f"{rate:.2f}" if rate < 10 else f"{rate:.1f}", size=12, weight="medium", color=clr)
71+
w.spacer()
72+
w.spacer()
73+
74+
else:
75+
with w.vstack(spacing=6):
76+
with w.hstack(spacing=6, align="center"):
77+
w.icon("dollarsign.circle.fill", size=18, color=accent)
78+
w.text("汇率转换器", size=17, weight="bold", color=txt_main)
79+
w.spacer()
80+
w.icon("clock", size=12, color=txt_sub)
81+
w.text(f"更新于 {now}", size=12, color=txt_sub)
82+
w.divider(color=("#E2E8F0", "#334155"))
83+
for flag, code, rate, trend in currencies:
84+
with w.hstack(spacing=6, align="center"):
85+
w.text(flag, size=16)
86+
w.text(code, size=14, weight="bold", color=txt_main)
87+
w.spacer()
88+
clr = up_clr if trend == "up" else down_clr
89+
arrow = "arrow.up.right" if trend == "up" else "arrow.down.right"
90+
w.icon(arrow, size=11, color=clr)
91+
w.text(f"{rate:.4f}" if rate < 10 else f"{rate:.2f}",
92+
size=15, weight="semibold", color=clr)
93+
if code != "CNY":
94+
w.divider(color=("#F1F5F9", "#1E293B"))
95+
96+
w.render()

0 commit comments

Comments
 (0)