AppJar module in Python - GeeksforGeeks

30 Jan, 2020
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.
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

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()

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()

# 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")

app.addLabel("title", " Hello World! ")

app.setLabelBg("title", "blue")

Lastly, run the app by appending the following command in your code:app.go()

app.go()

Complete code:
# Python program to demonstrate# hello world in appjar    # import the libraryfrom appJar import gui  # let app be name of gui # variableapp = gui()  # Adding the labelapp.addLabel("title", " Hello World! ")  # Setting the background colorapp.setLabelBg("title", "blue")app.go()
Output:
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.
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 – titleSyntax: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 entryapp.addEntry("entry_1")  # Setting the default valueapp.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 areacallFunction is set to False, if you do not want to call any associated functionsTo 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 areaapp.addTextArea("TA_1")  # Setting the default valueapp.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:# Python program to demonstrate# button widget of appjar    from appJar import gui    # Function to be passed# when the button is clickeddef clicked(btn):    print(btn)  app = gui()  # Adding the buttonapp.addButton("btn_one", clicked)  # Change the name of the buttonapp.setButton("btn_one", "Click me")  app.go()Output:After clicking the button:
Entry: This widget is used to get the typed input of the user and usually this widget takes a single parameter – titleSyntax: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 entryapp.addEntry("entry_1")  # Setting the default valueapp.setEntryDefault("entry_1",                     "This is an Entry field")  app.go()Output:
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 entryapp.addEntry("entry_1")  # Setting the default valueapp.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 areacallFunction is set to False, if you do not want to call any associated functionsTo 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 areaapp.addTextArea("TA_1")  # Setting the default valueapp.setTextArea("TA_1",                 "This is a Text field",                 end = True, callFunction = False)  app.go()Output:
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 areaapp.addTextArea("TA_1")  # Setting the default valueapp.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:# Python program to demonstrate# button widget of appjar    from appJar import gui    # Function to be passed# when the button is clickeddef clicked(btn):    print(btn)  app = gui()  # Adding the buttonapp.addButton("btn_one", clicked)  # Change the name of the buttonapp.setButton("btn_one", "Click me")  app.go()Output:After clicking the button:
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 clickeddef clicked(btn):    print(btn)  app = gui()  # Adding the buttonapp.addButton("btn_one", clicked)  # Change the name of the buttonapp.setButton("btn_one", "Click me")  app.go()
Output:
After clicking the button:
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:# Python program to demonstrate# label widget of appjar    from appJar import gui  app = gui()  # Adding the labelapp.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# Python program to demonstrate# message widget of appjar    from appJar import gui    app = gui()  # Adding the message labelapp.addLabel("label_1",             text ="This is a message label")  app.go()Output:
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 labelapp.addLabel("label_1",             text ="This is a label")  app.go()Output:
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 labelapp.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# Python program to demonstrate# message widget of appjar    from appJar import gui    app = gui()  # Adding the message labelapp.addLabel("label_1",             text ="This is a message label")  app.go()Output:
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 labelapp.addLabel("label_1",             text ="This is a message label")  app.go()
Output:
Python-gui
Technical Scripter 2019
Python
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Install PIP on Windows ?
How to drop one or multiple columns in Pandas Dataframe
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
Python | Pandas dataframe.groupby()
Defaultdict in Python
Python | Get unique values from a list
Python Classes and Objects
Python | os.path.join() method
Create a directory in Python