Sample to put Python Kivy in one file

#-*- coding: utf-8 -*-

from kivy.lang import Builder
Builder.load_string("""
<TextWidget>:
	BoxLayout:
		orientation: 'vertical'
		size: root.size

		TextInput:
			text: root.text

		Button:
			id: button1
			text: "OK"
			font_size: 48
			on_press: root.buttonClicked()
""")

from kivy.app import App
from kivy.uix.widget import Widget

from kivy.properties import StringProperty 

class TextWidget(Widget):
	text = StringProperty()

	def __init__(self, **kwargs):
		super(TextWidget, self).__init__(**kwargs)
		self.text = ''

	def buttonClicked(self):
		for i in range(5):
			self.text += str(i) + '\n'

class TestApp(App):
	def __init__(self, **kwargs):
		super(TestApp, self).__init__(**kwargs)
		self.title = 'greeting'

	def build(self):
		return TextWidget()

if __name__ == '__main__':
	TestApp().run()

The code is mostly a quote from what is written in the following articles. https://qiita.com/dario_okazaki/items/7892b24fcfa787faface

How do I combine the kv file and the python file into one? It's getting dull to google every time, so make a note for yourself

Recommended Posts

Sample to put Python Kivy in one file
I want to randomly sample a file in Python
[Itertools.permutations] How to put permutations in Python
PUT gzip directly to S3 in Python
Convert psd file to png in Python
Sample script to trap signals in Python
File operations in Python
One liner in Python
File processing in Python
One liner to 100% CPU1 core usage in Python
From file to graph drawing in Python. Elementary elementary
How to create a JSON file in Python
3 steps to put Python + mecab in yum only
File operations in Python
To add a module to python put in Julialang
How to drop Google Docs in one folder in a .txt file with python
Parse a JSON string written to a file in Python
A memorandum to run a python script in a bat file
[Work efficiency] How to change file names in Python
Download the file in Python
Login to website in Python
DMD in Python one dimension
Speech to speech in python [text to speech]
How to develop in Python
Post to Slack in Python
Change the standard output destination to a file in Python
Sample to put Python Flask web app on Azure App Service (Web App)
How to check ORM behavior in one file with django
How to import a file anywhere you like in Python
[Python] How to write an if statement in one sentence.
How to sample from any probability density function in Python
[Python] How to change EXCEL file saved in xlsb to xlsx
[Python Kivy] How to create an exe file with pyinstaller
Convert Excel file to text in Python for diff purposes
Make python segfault in one line
[Python] How to do PCA in Python
File / folder path manipulation in Python
Convert markdown to PDF in Python
[Python] Write to csv file with Python
Put MeCab in "Windows 10; Python3.5 (64bit)"
Save the binary file in Python
How to collect images in Python
Linebot creation & file sharing in Python
How to use SQLite in Python
Until you put Python in Docker
Output to csv file with Python
Progress bar in pop-up in Python Kivy
In the python command python points to python3.8
Create a binary file in Python
Try to calculate Trace in Python
How to convert 0.5 to 1056964608 in one shot
Try to put data in MongoDB
How to use Mysql in python
How to use ChemSpider in Python
6 ways to string objects in Python
ORC, Parquet file operations in Python
How to handle Japanese in Python
An alternative to `pause` in Python
File upload to Azure Storage (Python)
How to use python put in pyenv on macOS with PyCall
[Python] When you want to use all variables in another file