-1

So I am trying to make a clock using python and the eel library. I know i can easily make a clock using only JS and HTML, Im learning the eel library. I tried implementing a simple clock with python returning the value back to the html and html calling the funcion every 1 second. Does anyone know how to do this?

I have read this StackOverflow post: Sending data from Python to Javascript using EEL and I followed all of the instructions.

Code:

HTML:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Test</title>
  <style>
      body {
    background: black;
    color: #02feff;
  }
  textarea.a{
    font-size: 25px;
  }
  </style>
</head>
<body>
  <script type="text/javascript" src="/eel.js"></script>
  <script type="text/javascript" src="myscript.js"></script>
<script>
    setInterval(function(){thetime(); }, 1000);
</script>
<div id="output">Time: </div>
</body>
</html>

Python:

import eel
import requests
from datetime import datetime
eel.init('stacktest1/web')

@eel.expose
def thetime():
    now = datetime.now()
    current_time = now.strftime("%H:%M:%S")
    print("Current Time =", current_time)
    return current_time

try:
    eel.start('index.html', mode='chrome', host='localhost', port=8274)
except (SystemExit, MemoryError, KeyboardInterrupt):
    pass
print ('Closed browser log...!')

javascript

function callback(current_time){
    document.getElementById("output").value=current_time
};
function thetime(){
eel.thetime()(callback)
}

Now, using works, but i needed to replace as when I do so, the app doesn't show any error, nor shows any output of Time please spam ping me if you know thanks

1 Answers1

0

The div to be updated referenced by document.getElementById("output") doesn't have a value property, rather innerText or innerHTML. If you change this everything else seems to work properly.

document.getElementById("output").innerText=current_time
Woodford
  • 3,746
  • 1
  • 15
  • 29