1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| def _create_info_panel(self): """创建信息面板""" info_frame = self.info_frame ctk.CTkLabel(info_frame, text="列车基本参数", font=("Arial", 14, "bold")).pack(pady=10) params = { "车长": "23.4m", "列车编组": "6编组4动2拖", "列车质量": "194.295×10³ kg", "当前驾驶模式": "人工控制" } for key, value in params.items(): self._create_param_row(info_frame, key, value) self.dynamic_info_frame = ctk.CTkFrame(info_frame) self.dynamic_info_frame.pack(fill=tk.X, padx=5, pady=10) self.speed_display = ctk.CTkLabel(self.dynamic_info_frame, text="当前速度: 0.0 km/h", font=("Arial", 14)) self.speed_display.pack(pady=5) self.acceleration_display = ctk.CTkLabel(self.dynamic_info_frame, text="当前加速度: 0.0 m/s²", font=("Arial", 14)) self.acceleration_display.pack(pady=5) self.distance_display = ctk.CTkLabel(self.dynamic_info_frame, text=f"当前里程: {self.distance:.2f} m", font=("Arial", 14)) self.distance_display.pack(pady=5) self.control_state_display = ctk.CTkLabel(self.dynamic_info_frame, text="控制状态: 惰行", font=("Arial", 14)) self.control_state_display.pack(pady=5) def _create_param_row(self, parent, key, value): """创建参数行""" frame = ctk.CTkFrame(parent) frame.pack(fill=tk.X, padx=5, pady=2) ctk.CTkLabel(frame, text=key, anchor="w", width=100, font=("Arial", 12)).pack(side=tk.LEFT) ctk.CTkLabel(frame, text=value, anchor="w", font=("Arial", 12)).pack(side=tk.RIGHT) def _create_control_panel(self): """创建控制面板,将开始/结束按钮、重置按钮和倍速选择器放在同一行""" control_frame = ctk.CTkFrame(self.root) control_frame.pack(fill=tk.X, padx=10, pady=5) left_control_frame = ctk.CTkFrame(control_frame) left_control_frame.pack(side=tk.LEFT, fill=tk.X, expand=True) self.start_stop_button = ctk.CTkButton(left_control_frame, text="开始仿真", command=self._toggle_simulation) self.start_stop_button.pack(side=tk.LEFT, padx=5) self.reset_button = ctk.CTkButton(left_control_frame, text="重置仿真", command=self._reset_simulation, state="disabled") self.reset_button.pack(side=tk.LEFT, padx=5) speed_label = ctk.CTkLabel(left_control_frame, text="选择倍速:", font=("Arial", 12)) speed_label.pack(side=tk.LEFT, padx=(20, 5)) self.speed_multiplier_var = tk.DoubleVar(value=1.0) speed_options = [0.5, 1.0, 1.5, 2.0, 3.0, 5.0] self.speed_multiplier_menu = ctk.CTkOptionMenu(left_control_frame, variable=self.speed_multiplier_var, values=[str(x) for x in speed_options], command=self._set_speed_multiplier) self.speed_multiplier_menu.pack(side=tk.LEFT, padx=5) right_control_frame = ctk.CTkFrame(control_frame) right_control_frame.pack(side=tk.RIGHT, fill=tk.X, expand=True) self.time_label = ctk.CTkLabel(right_control_frame, text="仿真时间: 00:00", font=("Arial", 12)) self.time_label.pack(side=tk.RIGHT, padx=10) hint_label = ctk.CTkLabel(right_control_frame, text="操作提示:点击开始仿真并使用上下箭头控制速度", font=("Arial", 12)) hint_label.pack(side=tk.RIGHT, padx=20) def _set_speed_multiplier(self, value): """设置倍速系数""" self.simulation_speed_multiplier = float(value)
|