How to create a new html widget from an onclick event of an html button using js and python?

50 Views Asked by At

I have this html script (using css in another file):

h1 {
  text-align: center;
  font-family: andale mono, monospace;
}

h2 {
  text-align: center;
  font-family: andale mono, monospace;
}

#rcorners1 {
  border-radius: 5px;
  background: #d8cece;
}

.button-80 {
  background: #fff;
  backface-visibility: hidden;
  border-radius: .375rem;
  border-style: solid;
  border-width: .125rem;
  box-sizing: border-box;
  color: #212121;
  cursor: pointer;
  display: inline-block;
  font-family: andale mono, monospace;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.3;
  padding: .875rem 1.125rem;
  position: relative;
  text-align: left;
  text-decoration: none;
  transform: translateZ(0) scale(1);
  transition: transform .2s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.button-80:not(:disabled):hover {
  transform: scale(1.05);
}

.button-80:not(:disabled):hover:active {
  transform: scale(1.05) translateY(.125rem);
}

.button-80:focus {
  outline: 0 solid transparent;
}

.button-80:focus:before {
  content: "";
  left: calc(-1*.375rem);
  pointer-events: none;
  position: absolute;
  top: calc(-1*.375rem);
  transition: border-radius;
  user-select: none;
}

.button-80:focus:not(:focus-visible) {
  outline: 0 solid transparent;
}

.button-80:focus:not(:focus-visible):before {
  border-width: 0;
}

.button-80:not(:disabled):active {
  transform: translateY(.125rem);
}

.select-80 {
  background: #fff;
  backface-visibility: hidden;
  border-radius: .375rem;
  border-style: solid;
  border-width: .125rem;
  box-sizing: border-box;
  color: #212121;
  cursor: pointer;
  display: inline-block;
  font-family: andale mono, monospace;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.3;
  padding: .875rem 1.125rem;
  position: relative;
  text-align: left;
  text-decoration: none;
  transform: translateZ(0) scale(1);
  transition: transform .2s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.select-80:not(:disabled):hover {
  transform: scale(1.05);
}

.select-80:not(:disabled):hover:active {
  transform: scale(1.05) translateY(.125rem);
}

.select-80:focus {
  outline: 0 solid transparent;
}

.select-80:focus:before {
  content: "";
  left: calc(-1*.375rem);
  pointer-events: none;
  position: absolute;
  top: calc(-1*.375rem);
  transition: border-radius;
  user-select: none;
}

.btn-group {
  align-items: center;
}
<link href="web\Bootstrap\bootstrap.css" />
<script src="web\Bootstrap\bootstrap.js"></script>
<script type="text/javascript" src="/eel.js"></script>
<script type="text/javascript" src="/index.js"></script>
<link rel="stylesheet" href="/index.css">

<body style="background-color:#000000">

  <!-- This is the header section-->
  <h1 style="color:#ffffff">Welcome to Pashosh.</h1>
  <h2 style="color:#ffffff">Simple Navigation Tests Environment</h2>
  <!-- This is the main button section-->
  <div class="btn-group" style="width:100%">
    <button class="button-80" role="button" id="rcorners1" title="Choose the working directory" onclick="RunPythonOpenWorkingDir()">Working directory</button>
    <button class="button-80" role="button" id="rcorners1" title="Add a new test">Add</button>
    <button class="button-80" role="button" id="rcorners1" title="Remove marked tests">Remove</button>
    <button class="button-80" role="button" id="rcorners1" title="Save current test batch">Save</button>
    <button class="button-80" role="button" id="rcorners1" title="Load a test batch">Load</button>
    <button class="button-80" role="button" id="rcorners1" title="Run all tests">Run</button>
    <button class="button-80" role="button" id="rcorners1" title="Click here for documentation pdf file">Help</button>
  </div>
  <div>
  </div>
</body>

This python function:

root = tk.Tk()
root.withdraw()
Engine = engine.Engine()

eel.init("web")

@eel.expose
def WorkDirButtonFunc():      
    working_dir = filedialog.askdirectory()
    if working_dir is not None:
        return working_dir
    else:
        return None

I also got this empty js function:

  function RunPythonOpenWorkingDir() 
  { 

    eel.WorkDirButtonFunc()(function(work_dir)
    {
        
    });
  } 

I would like the working directory button to create a header that contains the chosen working directory that was chosen in the python function. How can I do it?

0

There are 0 best solutions below