Skip to content

Commit c62e702

Browse files
committed
use vars for default values
1 parent 20a4a01 commit c62e702

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

app.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
frame.pack(padx=10, pady=10)
1212
frame.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

1818
def 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

3535
def show_popup(title, message):
3636
messagebox.showinfo(title, message)
3737

3838
def 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

4343
def 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

4848
status = tk.Label(frame, text="", font=("Arial", 14), bg="lightblue")
4949
status.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)
5252
charge_slider.pack(pady=20)
5353
report_plug = tk.Label(frame, text="Report Charging Threshold", font=("Arial", 12))
5454
report_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)
5857
discharge_slider.pack(pady=20)
5958
report_unplug = tk.Label(frame, text="Report Discharging Threshold", font=("Arial", 12))
6059
report_unplug.pack()

0 commit comments

Comments
 (0)