class PowerClass(Structure): _fields_ = [('ACLineStatus', c_byte), ('BatteryFlag', c_byte), ('BatteryLifePercent', c_byte), ('Reserved1',c_byte), ('BatteryLifeTime',c_ulong), ('BatteryFullLifeTime',c_ulong)]
powerclass = PowerClass() result = windll.kernel32.GetSystemPowerStatus(byref(powerclass)) result = powerclass.BatteryLifePercent
while result<100: messagebox.showwarning("Warning", "Battery is lower than 100, please charge to 100") result = windll.kernel32.GetSystemPowerStatus(byref(powerclass)) result = powerclass.BatteryLifePercent else: RunBatteryLifeMS()#跑第1个