From 9eed4fe8e734df3bb309b55c7360e75ae1df498c Mon Sep 17 00:00:00 2001 From: lorhof1 <61967687+lorhof1@users.noreply.github.com> Date: Tue, 10 Aug 2021 21:01:33 +0200 Subject: [PATCH] Update main.py Improved performance by opening and closing the file only once, at the start and at the end instead of doing it every time the file is edited --- main.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 918467a..014d5ee 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,11 @@ import time, tkinter mode = "flash" color = "white" +f = open("/sys/devices/platform/clevo_xsm_wmi/kb_color", "w") #try to set the kb color to white, error if impossible try: - f = open("/sys/devices/platform/clevo_xsm_wmi/kb_color", "w") f.write("white") - f.close() print("sucessfully test set keyboard color") except: @@ -14,9 +13,7 @@ def setColor(passedColor): mode = "static" - f = open("/sys/devices/platform/clevo_xsm_wmi/kb_color", "w") f.write(passedColor) - f.close() print("sucessfully set keyboard color to " + passedColor) def flash(delay): @@ -57,4 +54,6 @@ def flash(delay): btnMagenta.pack() #btnFlash.pack() -window.mainloop() \ No newline at end of file +window.mainloop() + +f.close()