Giter Club home page Giter Club logo

myspa4's Introduction

GUI apps for Python

I was using Tkinter, but it was not simpler for me in case of UI design. I Personally like Electron for creating Desktop applications with javascript. I was searching for Electron like framework for Python and found eel. This project is basic tutorial for eel where we will create GUI app for desktop and call Python functions from Javascript and vice-versa.

Installation

We need eel, ntplib for our project to work.

pip install eel
pip install ntplib

Folder structure for our project will be as like as below diagram.

eel_basic
|
|----|app.py
|
|----|web
     |
     |----html
     |    |----index.html
     |
     |----css
     |    |----index.css
     |
     |----js
     |    |----index.js
     |
     |----image
          |----img.jpg

Let's Code

Clone the repository for running the exact code. I will describe how eel works. app.py should look like this.

import eel

# expose to javascript
@eel.expose
def ask_python_from_js_get_time(server):
    # DO SOMETHING

    # call javascript function
    eel.run_js_from_python(now_time)

# initialize the folder which contents html,js,css,etc
eel.init("web")

# start app
eel.start("html/index.html")

By defining a function with @eel.expose decorator, we will be able to access through Javascript. In this case we can access by calling eel.ask_python_from_js_get_time(arg) from javascript.

index.js should look like this.

// this function is called when button is clicked
function getCurrentTime() {
    // call python function
    eel.ask_python_from_js_get_time(server);
}

// this function will be executed from python
// msg is the argument received from python side
// it will show the message received to user
eel.expose(run_js_from_python);
function run_js_from_python(msg) {
    document.getElementById("result").innerHTML = msg;
}

By calling expose method with the function as argument, we will be able to access it through Python.

Run

Now, Open terminal and run this code from eel_basic folder.

python app.py

Your GUI app is ready.

myspa4's People

Contributors

dakc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.