from PyQt5 import QtWidgets
import glob
import time

def read_file(path):
    with open(path, 'r') as fh:
        return fh.read().strip()

class BatteryProvider(object):
    delay = 5

    def __init__(self, main_window):
        try:
            self.charge_now = glob.glob('/sys/class/power_supply/*/energy_now')[0]
            self.charge_max = glob.glob('/sys/class/power_supply/*/energy_full')[0]
            self.charge_status = glob.glob('/sys/class/power_supply/*/status')[0]
            self.battery_present = True
            self.label = QtWidgets.QLabel()
            main_window[0].right_widget.layout().addWidget(self.label)
        except IndexError:
            self.battery_present = False

    def refresh(self):
        if self.battery_present:
            now = int(read_file(self.charge_now))
            max = int(read_file(self.charge_max))
            self.status = read_file(self.charge_status).lower()
            self.percentage = now * 100.0 / max

    def render(self):
        if self.battery_present:
            self.label.setText('%3%%' % (self.percentage))

from PyQt5 import QtWidgets
import glob
import time

def read_file(path):
    with open(path, 'r') as fh:
        return fh.read().strip()

class BatteryProvider(object):
    delay = 5

    def __init__(self, main_window):
        try:
            self.charge_now = glob.glob('/sys/class/power_supply/*/energy_now')[0]
            self.charge_max = glob.glob('/sys/class/power_supply/*/energy_full')[0]
            self.charge_status = glob.glob('/sys/class/power_supply/*/status')[0]
            self.battery_present = True
            self.label = QtWidgets.QLabel()
            main_window[0].right_widget.layout().addWidget(self.label)
        except IndexError:
            self.battery_present = False

    def refresh(self):
        if self.battery_present:
            now = int(read_file(self.charge_now))
            max = int(read_file(self.charge_max))
            self.status = read_file(self.charge_status).lower()
            self.percentage = now * 100.0 / max

    def render(self):
        if self.battery_present:
            self.label.setText('%3.00f%%' % (self.percentage))

Fix battery widget