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:
- 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()
- 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")
- Lastly, run the app by appending the following command in your code:
app.go()
Complete code:
Python3
# 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:
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.
- 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:
Python3 1==
# 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:
- 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
Python3 1==
# 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:
- 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:
Python3 1==
# 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:
After clicking the button:
Output Widgets
These widgets are used to display some information to the user who is interacting with the app.
- 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:
Python3 1==
# 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:
- 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
Python3 1==
# 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:
Similar Reads
Import module in Python In Python, modules allow us to organize code into reusable files, making it easy to import and use functions, classes, and variables from other scripts. Importing a module in Python is similar to using #include in C/C++, providing access to pre-written code and built-in libraries. Pythonâs import st
3 min read
Python Module Index Python has a vast ecosystem of modules and packages. These modules enable developers to perform a wide range of tasks without taking the headache of creating a custom module for them to perform a particular task. Whether we have to perform data analysis, set up a web server, or automate tasks, there
4 min read
External Modules in Python Python is one of the most popular programming languages because of its vast collection of modules which make the work of developers easy and save time from writing the code for a particular task for their program. Python provides various types of modules which include built-in modules and external m
5 min read
Python Fire Module Python Fire is a library to create CLI applications. It can automatically generate command line Interfaces from any object in python. It is not limited to this, it is a good tool for debugging and development purposes. With the help of Fire, you can turn existing code into CLI. In this article, we w
3 min read
Python Math Module Math Module consists of mathematical functions and constants. It is a built-in module made for mathematical tasks. The math module provides the math functions to deal with basic operations such as addition(+), subtraction(-), multiplication(*), division(/), and advanced operations like trigonometric
13 min read
Python Modules Python Module is a file that contains built-in functions, classes,its and variables. There are many Python modules, each with its specific work.In this article, we will cover all about Python modules, such as How to create our own simple module, Import Python modules, From statements in Python, we c
7 min read
Create and Import modules in Python In Python, a module is a self-contained Python file that contains Python statements and definitions, like a file named GFG.py, can be considered as a module named GFG which can be imported with the help of import statement. However, one might get confused about the difference between modules and pac
3 min read
Built-in Modules in Python Python is one of the most popular programming languages because of its vast collection of modules which make the work of developers easy and save time from writing the code for a particular task for their program. Python provides various types of modules which include Python built-in modules and ext
9 min read
How to Install a Python Module? A module is simply a file containing Python code. Functions, groups, and variables can all be described in a module. Runnable code can also be used in a module. What is a Python Module?A module can be imported by multiple programs for their application, hence a single code can be used by multiple pr
4 min read
Basics Of Python Modules A library refers to a collection of modules that together cater to a specific type of needs or application. Module is a file(.py file) containing variables, class definitions statements, and functions related to a particular task. Python modules that come preloaded with Python are called standard li
3 min read