How to run Python script directly in Kivy file?
Kivy is a platform-independent GUI tool in Python. It can run on Android, IOS, Linux and Windows, etc. This is the only GUI library from python which can independently run on the android device even we can use it on Raspberry pi also. It is an open-source Python library for the rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. Its graphic engine is built over OpenGL ES 2, and has fast graphics pipeline. If you are new to kivy you can learn from this link.
In this article, we will develop a GUI window using kivy framework of python and we will add a button on this window. Usually what happens is we attach a method to a button and the whole method is defined in another python file but this time we will add button code to same .kv file
The IDE we are going to use is pycharm and the version of python we are going to use is python 3.6.
- Create new project in pycharm
- Installing required packages
- Add new python file in venv directory of your project. To add file video has been attaches.
- Add new .kv file in project. Implementation us depicted here:
- Adding code to both files
window which contains our button:
# adding a button
# text which will appear on button
text:”click here to open google search”
#importing webbrowser module
# it will open google window in your browser
print(“see these scripts are now running using kivy file”)
when you click on button then it will open the google page and print the content of print statement defined in ui.kv file on terminal, you can see in the given video.