芯片解密,芯片破解,IC解密,单片机解密,MCU解密,STM解密

飞芯科技提供芯片解密,芯片破解,IC解密,单片机解密,MCU解密,STM解密逆向服务

单片机解密python程序制作时钟的源码

单片机解密python程序制作时钟的源码芯片解密

  1. import tkinter as tk
  2. import math
  3. import time
  4. import threading
  5. import socket
  6. import datetime

  7. class AnalogClock:
  8.     def __init__(self, root):
  9.         self.root = root
  10.         self.root.title("Python 模拟钟表(可缩放)")
  11.         self.root.minsize(200, 200)          # 最小窗口尺寸

  12.         self.canvas = tk.Canvas(root, bg='white')
  13.         self.canvas.pack(fill=tk.BOTH, expand=True)

  14.         # 中心点和半径(将在 draw_face 中计算)
  15.         self.center_x = 200
  16.         self.center_y = 200
  17.         self.radius = 180

  18.         # 时间变量
  19.         self.hour = 0
  20.         self.minute = 0
  21.         self.second = 0
  22.         self.use_system_time = True

  23.         # 绑定窗口大小变化事件
  24.         self.canvas.bind("<Configure>", self.on_resize)

  25.         # 初次绘制表盘和启动时钟更新
  26.         self.draw_face()
  27.         self.update_clock()

  28.         # 启动 TCP 服务器(独立线程)
  29.         self.server_thread = threading.Thread(target=self.start_tcp_server, daemon=True)
  30.         self.server_thread.start()

  31.     def draw_face(self):
  32.         """根据当前画布尺寸重绘表盘(刻度、数字),同时更新中心点和半径"""
  33.         # 删除旧表盘元素(保留指针,因为指针由 update_clock 管理)
  34.         self.canvas.delete("face")

  35.         # 获取当前画布尺寸
  36.         w = self.canvas.winfo_width()
  37.         h = self.canvas.winfo_height()
  38.         if w < 10 or h < 10:
  39.             return  # 避免初始尺寸过小
  40.         self.center_x = w // 2
  41.         self.center_y = h // 2
  42.         self.radius = min(w, h) // 2 - 20   # 留出边距

  43.         # 绘制 12 个刻度及数字
  44.         for i in range(12):
  45.             angle = math.radians(i * 30 - 90)  # 12点方向为0度
  46.             # 长刻度线
  47.             x1 = self.center_x + (self.radius - 10) * math.cos(angle)
  48.             y1 = self.center_y + (self.radius - 10) * math.sin(angle)
  49.             x2 = self.center_x + (self.radius - 25) * math.cos(angle)
  50.             y2 = self.center_y + (self.radius - 25) * math.sin(angle)
  51.             self.canvas.create_line(x1, y1, x2, y2, width=3, tags="face")
  52.             # 数字
  53.             num_x = self.center_x + (self.radius - 40) * math.cos(angle)
  54.             num_y = self.center_y + (self.radius - 40) * math.sin(angle)
  55.             self.canvas.create_text(num_x, num_y, text=str(i+1),
  56.                                     font=('Arial', int(self.radius/10), 'bold'),
  57.                                     tags="face")

  58.         # 中心圆点(始终在最上层,用单独的 tag 或不参与删除)
  59.         self.canvas.create_oval(self.center_x-8, self.center_y-8,
  60.                                 self.center_x+8, self.center_y+8,
  61.                                 fill='black', tags="face")

  62.     def on_resize(self, event):
  63.         """窗口尺寸变化时重绘表盘(指针由 update_clock 自动适配)"""
  64.         self.draw_face()

  65.     def update_clock(self):
  66.         """每秒更新指针(使用当前中心点和半径)"""
  67.         # 获取系统时间(若处于系统模式)
  68.         if self.use_system_time:
  69.             now = datetime.datetime.now()
  70.             self.hour = now.hour % 12
  71.             self.minute = now.minute
  72.             self.second = now.second

  73.         # 删除旧指针
  74.         self.canvas.delete("hands")

  75.         # 计算角度(12点方向为0度)
  76.         sec_angle = math.radians(self.second * 6 - 90)
  77.         min_angle = math.radians((self.minute + self.second/60) * 6 - 90)
  78.         hour_angle = math.radians((self.hour + self.minute/60) * 30 - 90)

  79.         # 绘制指针(长度相对半径)
  80.         self.draw_hand(sec_angle, self.radius * 0.85, width=1, color='red', tag='hands')
  81.         self.draw_hand(min_angle, self.radius * 0.70, width=3, color='blue', tag='hands')
  82.         self.draw_hand(hour_angle, self.radius * 0.50, width=5, color='black', tag='hands')

  83.         # 继续下一帧
  84.         self.root.after(1000, self.update_clock)

  85.     def draw_hand(self, angle, length, width=2, color='black', tag=''):
  86.         x = self.center_x + length * math.cos(angle)
  87.         y = self.center_y + length * math.sin(angle)
  88.         self.canvas.create_line(self.center_x, self.center_y, x, y,
  89.                                 width=width, fill=color, tags=tag)

  90.     # ---------- TCP 服务器(保持不变) ----------
  91.     def start_tcp_server(self):
  92.         host = '127.0.0.1'
  93.         port = 8888
  94.         with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
  95.             s.bind((host, port))
  96.             s.listen(1)
  97.             print(f"TCP 服务器已启动,监听 {host}:{port}")
  98.             while True:
  99.                 conn, addr = s.accept()
  100.                 with conn:
  101.                     print(f"连接来自 {addr}")
  102.                     while True:
  103.                         data = conn.recv(1024).decode().strip()
  104.                         if not data:
  105.                             break
  106.                         response = self.process_command(data)
  107.                         conn.sendall(response.encode())
  108.                         if data.lower() =



联系方式

地址:石家庄市新华区民族路77号华强广场D座2009
电话:0311-88816616/87087811
手机:13315190088
传真:0311-67901001
联系人:张工
网址:www.taihedz.cn
邮箱:feixindz@163.com
微信:xinpianjiemi
QQ:527263666/568069805

在线客服
热线电话

企业微信