Create a Python application with a GUI using TKinter's wrapper called Appjar.
OS: Windows10 Python: 2.7.15
pip install appjar
The basic flow is as follows. ① Library import ② Create GUI instance (base) ③ Add widget ④ Create a corresponding function for the widget that generates an event such as Button. ⑤ Start GUI
See Official for more information. The following is a slight modification of the official Hello World.
SimpleGUI.py
# -*- coding: utf-8 -*-
#① Import library
from appJar import gui
#② Create a GUI instance
#Format: app = gui("Window name","vertical x width")
app = gui("Login Window", "400x200")
#Specifying the overall background color, text color and font
app.setBg("black")
app.setFg("white")
app.setFont(16)
#(3) Define a function to link with the event on the GUI
def press(button):
if button == "Cancel":
app.stop()
else:
usr = app.getEntry("Username")
pwd = app.getEntry("Password")
print("User:", usr, "Pass:", pwd)
#④ Add widgets to the base instance.
app.addLabel("title", "Welcome to appJar")
app.setLabelBg("title", "lightblue")
app.setLabelFg("title", "black")
app.addLabelEntry("Username")
app.addLabelSecretEntry("Password")
# "Submit","Cancel"Create two buttons, and specify the press function as the corresponding action.
app.addButtons(["Submit", "Cancel"], press)
# "Username"Set focus on
app.setFocus("Username")
#⑤ Start GUI. Basically, do not write any code after this.
app.go()
As a rough reminder, the attributes of gui () are (add or set) + (widget name) + (parameter name) The argument is ("Attribute name", "Parameter value") It seems that it is. In add, the parameter part may be only the argument part. For example, app.setLabelBg ("title", "lightblue") The value of the Bg parameter of the Label widget named title, It is in the form of being changed (set) to the value lightblue.
List of available widgets http://appjar.info/pythonWidgets/ However, here are just some of the parameters that can be changed for each widget. For example, if you look only here, you can't set the background for Message, but that's not the case, and the basic parameters (Bg, Fg, Width, etc.) are the same. See here for more details on the configurable parameters.
I personally think Appjar is more intuitive and straightforward than TKinter. However, it was a little difficult to understand the layout of the documents, so I feel that the hurdle to start using is a little high. I hope this article helps you.
Recommended Posts