🍪
Jump to language selection Jump to main navigation Jump to content Jump to footer navigation

Add Battery Icon To Taskbar

It’s a frustrating moment: you glance at the bottom of your laptop screen to check how much juice you have left, only to realize the battery icon has vanished. Without that icon, you lose the ability to quickly check your percentage or switch power modes.

@objc private func toggleMenu() statusItem?.menu?.popUp(positioning: nil, at: NSEvent.mouseLocation, in: nil) add battery icon to taskbar

menu = pystray.Menu( pystray.MenuItem("Battery Status", self.show_battery_info), pystray.MenuItem("Exit", self.exit_app) ) It’s a frustrating moment: you glance at the

func applicationDidFinishLaunching(_ notification: Notification) batteryStatusItem = BatteryStatusItem() add battery icon to taskbar

# Show battery icon in taskbar $registryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"

if let button = statusItem?.button button.title = getBatteryPercentage() button.action = #selector(toggleMenu) button.target = self

def show_battery_info(self): percent, is_charging = self.get_battery_status() status = f"Battery: percent%\n" status += "Charging" if is_charging else "Discharging"