0

Good Day,

I'm having a problem with my program. My program is a time-based schedule of switching the lights on and off which basically needs to update time to time every seconds. But whenever I set a time-schedule in my "SET TIME" button, by the time I click it, it is set but it doesn't keep an update and you have to click "SET TIME" again to make an update about the time you inputted. My goal is to set a time-based schedule which whenever I click once will automatically update according to time until it will reach according to the real time.

MY PythonTkinter/ARDUINO CODE:

from tkinter import *
import datetime
import time
import time as tm
import random
import os
import sys
from tkinter.ttk import Combobox
import time as tm
import serial
from serial import Serial
import tkinter
ser1 = serial.Serial('COM6', 9600)


def led_off():
    ser1.write(b'0')


def led_on():
    ser1.write(b'1')


window = Tk()
window.geometry("800x400")
window.title("Automated Light Integrated System")


def save_info():
    onhour_info = onHour.get()
    onmin_info = onMin.get()
    offhour_info = offHour.get()
    offmin_info = offMin.get()
    x = datetime.datetime.now()

    print("Congratulations! You just set an Starting Time of", onhour_info, ":", onmin_info)
    print("Congratulations! You just set an Ending Time of", offhour_info, ":", offmin_info)

    if onhour_info == x.strftime('%H') and onmin_info == x.strftime('%M'):
        led_on()

    elif offhour_info == x.strftime('%H') and offmin_info == x.strftime('%M'):
        led_off()


label1 = Label(window, text="Welcome User!", font=("arial", 24, "bold"), relief="solid").place(x=300, y=10)


def clock():
    time_string = time.strftime("%H:%M:%S")
    label2.config(text=time_string)
    label2.after(1000, clock)


label2 = Label(window, font=("arial", 10), relief="solid")
label2.place(x=700, y=10)

clock()

label3 = Label(window, text="Please Indicate your Starting Time", font=("arial", 12)).place(x=30, y=90)
onHour = StringVar()
label4 = Label(window, text="Hour(s) ", font=("arial", 10)).place(x=10, y=120)
hour_entry = Entry(textvariable=onHour, width="5").place(x=60, y=121)

onMin = StringVar()
label5 = Label(window, text="Minute(s) ", font=("arial", 10)).place(x=90, y=120)
min_entry = Entry(textvariable=onMin, width="5").place(x=150, y=120)

register1 = Button(window, text="Set Time", width="20", height="2", command=save_info).place(x=300, y=120)

label6 = Label(window, text="Please Indicate your Ending Time: ", font=("arial", 12)).place(x=500, y=90)
offHour = StringVar()
label7 = Label(window, text="Hour(s) ", font=("arial", 10)).place(x=500, y=120)
hour_entry = Entry(textvariable=offHour, width="5").place(x=550, y=121)

offMin = StringVar()
label8 = Label(window, text="Minute(s) ", font=("arial", 10)).place(x=570, y=120)
min_entry = Entry(textvariable=offMin, width="5").place(x=630, y=120)


window.mainloop()

THE ACTUAL PHOTO: enter image description here

Error is the least I have problem for now. Thank you for your kind response!

j_4321
  • 15,431
  • 3
  • 34
  • 61
  • Just to clarify, you would like it to not need a "Set Time" button and just update the values autmatically when you enter them in the input boxes? – Hymns For Disco Nov 17 '19 at 09:55
  • Read through this thread, I think this is what you're after https://stackoverflow.com/questions/6548837/how-do-i-get-an-event-callback-when-a-tkinter-entry-widget-is-modified – Hymns For Disco Nov 17 '19 at 09:58
  • Thank you one again for response! so basically i have to delete my button? then whenver I inputed a variable in my input box it will automatically set a time accordingly? i'll read the link you send – Teddy Ramos Nov 17 '19 at 10:07

0 Answers0