Double-click to apply, then restart File Explorer.
private func startMonitoring() timer = Timer.scheduledTimer(withTimeInterval: 60, repeats: true) [weak self] _ in DispatchQueue.main.async self?.statusItem?.button?.title = self?.getBatteryPercentage() ?? "??%" add battery icon to taskbar
def create_battery_icon(self, percent, is_charging): # Create icon image size = 64 image = Image.new('RGBA', (size, size), (0, 0, 0, 0)) draw = ImageDraw.Draw(image) # Battery outline draw.rectangle( [(8, 20), (56, 44)], outline='white', width=2 ) # Battery terminal draw.rectangle( [(56, 28), (60, 36)], fill='white' ) # Battery level fill_width = int(48 * (percent / 100)) draw.rectangle( [(10, 22), (10 + fill_width, 42)], fill='#00ff00' if percent > 20 else '#ff0000' ) # Charging indicator if is_charging: draw.line([(28, 12), (36, 12)], fill='#00ff00', width=2) draw.line([(32, 12), (32, 20)], fill='#00ff00', width=2) return image Double-click to apply, then restart File Explorer
def show_battery_info(self): percent, is_charging = self.get_battery_status() status = f"Battery: percent%\n" status += "Charging" if is_charging else "Discharging" # Create popup window root = tk.Tk() root.title("Battery Status") root.geometry("300x150") label = tk.Label(root, text=status, font=("Arial", 12)) label.pack(pady=20) progress = ttk.Progressbar(root, length=200, mode='determinate') progress['value'] = percent progress.pack(pady=10) tk.Button(root, text="Close", command=root.destroy).pack(pady=10) root.mainloop() Double-click to apply