1

I'm tracking my current battery percent right from the time it was unplugged from time to time.

Sometimes I need to use the device (Windows 10 64 bit) even if it's not fully charge, so sometimes I unplug it at 86%, 95%, 82%, etc. so I need to track it.

I made a script to get the current time and then add it to clipboard so I can paste it somewhere.

Here's the whole code:

from tkinter import *
from urllib import parse
from tkinter import Tk
import tkinter.ttk as ttk
from datetime import datetime


root = Tk() 
root.title("Current Time")
root.geometry('250x57+1000+103')

lbl = Label(root, text="Time")
lbl.pack()

def clicked():

    d = datetime.now()
    print(d.strftime("%I:%M"))

    root.clipboard_clear()
    root.clipboard_append(d.strftime("%I:%M %p"))
    lbl.configure(text= d.strftime("%I:%M %p"))

style = ttk.Style(root)
style.theme_use('clam')
style.configure('TButton', bordercolor="black")

btn = ttk.Button(root, text='Show Current Time', style='TButton', command=clicked, width = 37)
btn.pack()

root.wm_attributes("-topmost", 1)
root.mainloop()

Right now, only "11:41 AM" will be display and appended to clipboard.

I want something like:

def clicked():

    d = datetime.now()

    batt = root.detect_current_battery()

    root.clipboard_clear()
    root.clipboard_append(d.strftime("%I:%M %p batt"))
    lbl.configure(text= d.strftime("%I:%M %p batt"))

... so that I can get the current time as well as the current battery percent (11:41 AM 86%) and paste it somewhere.

I found this thread but I'm not sure how to use this code:

battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'` 

...to what I'm trying to achieve.

yalpsid
  • 235
  • 1
  • 13
  • 2
    Have you seen this: https://stackoverflow.com/questions/45626937/how-to-get-battery-percentage-with-python – arshajii Jan 20 '19 at 04:06
  • That code looks like Bash. You'd probably need to install Cygwin or similar, and even then it might not work. – Mad Physicist Jan 20 '19 at 04:06
  • The code is for Ubuntu Linux. It won't run on Windows as it is not Linux. It will also not run on Cygwin since that still lacks the kernel interface to the power management. – Klaus D. Jan 20 '19 at 04:17

0 Answers0