Open In App

AppJar module in Python

Last Updated : 30 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The appJar library is designed to provide the easiest way to create a GUI using Python. It is a wrapper around the Tkinter, to allow the secondary school students to develop simple GUI in Python. appJar is designed in such a way that it can run on many versions of Python so it would be really easy to work with beginners.

Installation

The appJar library is designed to primarily work in schools, it therefore requires no specific installation.
Any Python programmer can just Download the zip file, unzip it and use the library after copying it inside the source code folder.

It also supports installation using the following command :

pip install appjar

Getting Started

To create an appJar app:

  1. Import gui from appJar library and create gui variable.
    For this add the following line at the beginning of the source code file

    # import the library
    from appJar import gui
    
    # let app be name of gui variable
    app = gui()
    
  2. Using the app variable, configure the application look and logic of each widget.
    For example, here we are creating a window which displays “Hello World” using the app variable.

    app.addLabel("title", " Hello World! ")
    
    app.setLabelBg("title", "blue")
    
  3. Lastly, run the app by appending the following command in your code:
    app.go()
    

Complete code:




# Python program to demonstrate
# hello world in appjar
  
  
# import the library
from appJar import gui
  
# let app be name of gui 
# variable
app = gui()
  
# Adding the label
app.addLabel("title", " Hello World! ")
  
# Setting the background color
app.setLabelBg("title", "blue")
app.go()


Output:

appjar-hello-world

Widgets

There are two types of widgets: Input widgets and output widgets. Widgets usually have three common functions:

  • add – this function is used to add the widget to the app
  • get – this function is used to get the content of the widget
  • set – this function is used to change the content or configure the widget

For each of the above functions, the first parameter will always be the title of the widget. Some of the commonly used widgets are mentioned below.

Input Widgets

These are used to record user interaction with the app via click, drag or typing.

  1. Entry: This widget is used to get the typed input of the user and usually this widget takes a single parameter – title

    Syntax:

    app.addEntry("entryTitle")

    You can set the default value to an entry using:

     app.setEntryDefault("entryTitle", "defaultText")

    To get the value of a specific entry use:

     app.getEntry("entryTitle") 

    To get the value of all entries use.

     app.getAllEntries()

    Note: this will return content of all entries as a dictionary.

    Example:




    # Python program to demonstrate
    # entry widget appjar
      
      
    from appJar import gui
      
    app = gui()
      
    # Adding the entry
    app.addEntry("entry_1")
      
    # Setting the default value
    app.setEntryDefault("entry_1"
                        "This is an Entry field")
      
    app.go()

    
    

    Output:

    appjar-entry-field

  2. TextArea: This widget is used to get the typed input of the user but unlike the Entry field, it supports typing text over multiple lines.

    Syntax:

    app.addTextArea("textAreaTitle", text=None)

    You can add text to specified text area using:

     app.setTextArea("textAreaTitle", 
                          "someText", 
                          end = True, 
                          callFunction = True)
    • By default, text is added at end of the text area by setting end = False in parameter, you can append text at beginning of the text area
    • callFunction is set to False, if you do not want to call any associated functions

    To get the value of a specific textarea use:

    app.getTextArea("textAreaTitle")

    To get contents of all text areas use.

    app.getAllTextAreas()

    Note: this will return the content of all entries as a dictionary.

    Example




    # Python program to demonstrate
    # textarea widget appjar
      
      
    from appJar import gui
      
      
    app = gui()
      
    # Adding text area
    app.addTextArea("TA_1")
      
    # Setting the default value
    app.setTextArea("TA_1"
                    "This is a Text field"
                    end = True, callFunction = False)
      
    app.go()

    
    

    Output:

    appjar-textarea

  3. Button: Button is used to call specific function and make app more interactive with user.

    Syntax:

     app.addButton("buttonTitle", functionName ) 

    Here, functionName should be specified, which will be called when the button is clicked, where the title is passed as a parameter to the called function.

    You can change the name of the button but not the value passed as parameter by using:

     app.setButton("buttonTitle", "someText")

    You can also place an image on the button instead of text using:

     app.setButtonImage("buttonTitle", "imagePath", align=None)

    If align is set then the image will be aligned relative to the text else the image will simply replace the text.

    Example:




    # Python program to demonstrate
    # button widget of appjar
      
      
    from appJar import gui
      
      
    # Function to be passed
    # when the button is clicked
    def clicked(btn):
        print(btn)
      
    app = gui()
      
    # Adding the button
    app.addButton("btn_one", clicked)
      
    # Change the name of the button
    app.setButton("btn_one", "Click me")
      
    app.go()

    
    

    Output:

    appjar-button

    After clicking the button:

    appjar-button-2

Output Widgets

These widgets are used to display some information to the user who is interacting with the app.

  1. Label: Labels are used for displaying texts on the app.

    Syntax:

    app.addLabel("labelTitle", text="someText")

    Here, if text is set to None then the title of the label will be displayed in the label output widget in the app.

    You can change the content of label by using:

    app.setLabel("labelTitle", "someText")

    You get the contents of the label using:

    app.getLabel("labelTitle")

    Example:




    # Python program to demonstrate
    # label widget of appjar
      
      
    from appJar import gui
      
    app = gui()
      
    # Adding the label
    app.addLabel("label_1",
                 text ="This is a label")
      
    app.go()

    
    

    Output:

    appjar-label

  2. Message: The Message widget is used for displaying texts over multiple lines on the app.

    Syntax:

    app.addMessage("messageTitle", text="someText")

    Here, if the text is set to None then the title of the Message widget will be displayed in the Message output widget in the app.

    You can change the content of Message by using:

    app.setMessage("messageTitle", "someText")

    You clear contents of specified Message widget using:

    app.clearMessage("messageTitle")

    Example




    # Python program to demonstrate
    # message widget of appjar
      
      
    from appJar import gui
      
      
    app = gui()
      
    # Adding the message label
    app.addLabel("label_1",
                 text ="This is a message label")
      
    app.go()

    
    

    Output:

    appjar-message



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads