1111frame .pack (padx = 10 , pady = 10 )
1212frame .pack_propagate (False )
1313
14- charging_threshold = 10
15- discharging_threshold = 100
14+ charging_threshold = tk . DoubleVar ( value = 30 )
15+ discharging_threshold = tk . DoubleVar ( value = 100 )
1616
1717
1818def update_battery_label ():
@@ -24,37 +24,36 @@ def update_battery_label():
2424 status .config (text = f"Battery: { battery_percent } %, Discharging" , fg = "red" )
2525
2626 # Check if battery is below discharging threshold
27- if battery_percent <= charging_threshold and not (isCharging ):
27+ if battery_percent <= int ( charging_threshold . get ()) and not (isCharging ):
2828 show_popup ("Charge Now" , "Your battery is below the discharging threshold. Plug in your charger." )
2929
30- if battery_percent >= discharging_threshold and isCharging :
30+ if battery_percent >= int ( discharging_threshold . get ()) and isCharging :
3131 show_popup ("Charge Now" , "Your battery is above the charging threshold. Remove your charger." )
3232
33- root .after (2000 , update_battery_label ) # Update every 1000 milliseconds (1 second )
33+ root .after (2000 , update_battery_label ) # Update every 2000 milliseconds (2 seconds )
3434
3535def show_popup (title , message ):
3636 messagebox .showinfo (title , message )
3737
3838def plug_label (value ):
3939 report_plug .config (text = f"Report to Plug Charger at { value } %" , fg = "blue" )
4040 global charging_threshold
41- charging_threshold = int ( value )
41+ charging_threshold = tk . DoubleVar ( value = value )
4242
4343def unplug_label (value ):
4444 report_unplug .config (text = f"Report to Unplug Charger at { value } %" , fg = "orange" )
4545 global discharging_threshold
46- discharging_threshold = int ( value )
46+ discharging_threshold = tk . DoubleVar ( value = value )
4747
4848status = tk .Label (frame , text = "" , font = ("Arial" , 14 ), bg = "lightblue" )
4949status .pack ()
5050
51- charge_slider = tk .Scale (frame , from_ = 0 , to = 100 , variable = 0 , orient = tk .HORIZONTAL , length = 300 , command = plug_label )
51+ charge_slider = tk .Scale (frame , from_ = 0 , to = 100 , variable = charging_threshold , orient = tk .HORIZONTAL , length = 300 , command = plug_label )
5252charge_slider .pack (pady = 20 )
5353report_plug = tk .Label (frame , text = "Report Charging Threshold" , font = ("Arial" , 12 ))
5454report_plug .pack ()
5555
56- default_value = tk .DoubleVar (value = 100 )
57- discharge_slider = tk .Scale (frame , from_ = 0 , to = 100 , variable = default_value ,orient = tk .HORIZONTAL , length = 300 , command = unplug_label )
56+ discharge_slider = tk .Scale (frame , from_ = 0 , to = 100 , variable = discharging_threshold ,orient = tk .HORIZONTAL , length = 300 , command = unplug_label )
5857discharge_slider .pack (pady = 20 )
5958report_unplug = tk .Label (frame , text = "Report Discharging Threshold" , font = ("Arial" , 12 ))
6059report_unplug .pack ()
0 commit comments