I am creating an application using Python Kivy that would take the user's input and create an Excel file storing the input.
I tried using openpyxl but the app crashes before starting on my android phone but on a desktop computer, it works perfectly. Is it possible to modify Excel files on my Android phone using Kivy and Openpyxl?
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
import openpyxl
class MyApp(App):
def build(self):
return MyGrid()
class MyGrid(GridLayout):
def __init__(self,**kwargs):
self.submit = Button(text='Submit', font_size=30)
self.submit.bind(on_press=self.pressed2)
self.add_widget(self.submit)
def pressed2(self,instance):
wb = openpyxl.Workbook()
ws = wb.active
ws['A1']='Hello'
wb.save('Trial.xlsx')
if __name__ == "__main__":
MyApp().run()
I use Kivy Launcher and the app crashes but if I remove all openpyxl stuff and put any other function, it works perfectly. I'm expecting it to create an Excel file on my phone. If this is not possible, what can I do instead?
It looks like it's probably a pure python library so it's likely to work without issues on Android, but you'll need to build an APK that actually includes it. It might also turn out that it does have dependencies that are hard to build for some reason, but you'll have to try it to see.
Related
I'm trying to make an android app that opens a pdf file on a click of a button. I am using the modules kivy as gui, subprocess to open a pdf and it worked on my PC but after converting it to an apk with buildozer, the gui works but the button to open a pdf is not working, the button can be seen that it is being pressed but does not do its function. I tried to find the mistake in my code, searching what's wrong and then I found a statement that says the subprocess module does not work on android.
I then used the webbrowser module, same as above it was working on my PC but after it got converted the gui works but when the I click the button that opens a pdf, the app crashes. I would like to see if there's a fix using webbrowser as it looks more promising than looking for another module
Below are the .py files for the one I used subprocess on and then webbrowser.
Using webbrowser
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
import webbrowser
file_path = r"file://C:\Users\...\...\...\sample.pdf"
class WelcomeScreen(Screen):
pass
class SecondScreen(Screen):
def openPDF(self):
webbrowser.open_new(file_path)
class WindowManager(ScreenManager):
pass
kv = Builder.load_file('design.kv')
class MAINAPP(App):
def build(self):
return kv
if __name__ == '__main__':
MAINAPP().run()
Using Subprocess
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
import webbrowser
file_path = "C:\Users\...\...\...\sample.pdf"
class WelcomeScreen(Screen):
pass
class SecondScreen(Screen):
def openPDF(self):
subprocess.Popen((file_path), shell=True)
class WindowManager(ScreenManager):
pass
kv = Builder.load_file('design.kv')
class MAINAPP(App):
def build(self):
return kv
if __name__ == '__main__':
MAINAPP().run()
I have a simple python kivy source code (only a example) and I execute the code in virtuelenv. The "program" runs without errors.
But unfortunately I see not the open window - only the Python Icon on the bottom from my task bar.
What I have to do that the windows opens?
# Datei: hello.py
import kivy
kivy.require('1.9.0') # Mindest-Version von Kivy
from kivy.app import App
from kivy.uix.button import Button
class HelloApp(App):
def build(self):
return Button(text='Hallo Welt!')
if __name__== "__main__":
HelloApp().run()
image
Pls help. I'm trying to learn the basics but it won't display exactly as I expected it to. Only blank screen appears and no button. importing button also does not help.
main.py
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
[enter image description here][1]
class NoobWidget(BoxLayout):
pass
class NoobApp(App):
def build(self):
return NoobWidget()
if __name__ =="__main__":
NoobApp().run()
kivytesta.kv
<NoobWidget>
Button:
text:"Click me"
Label:
text:"Not Clicked Yet"
You must load the kv file:
class NoobApp(App):
def build(self):
Builder.load_file('kivytesta.kv')
return NoobWidget()
I haven't tried the suggested fix advised but after installing python on a new laptop, I saw in the release notes that back then that latest version of kivy was not compatible to the python 3.x version I was using. Now I am using the latest version of Kivy 2.0.0 and it worked.
So i downloaded the "kivy" module (using the 'command prompt') as shown during this video "https://www.youtube.com/watch?v=B79miUFD_ss&list=PLGLfVvz_LVvTAZ-OcNIXe05srJRXaJRd9"
But whenever i try to run this code:
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.button import Label
# Inherit Kivy's App class which represents the window
# for our widgets
# HelloKivy inherits all the fields and methods
# from Kivy
class HelloKivy(App):
# This returns the content we want in the window
def build(self):
# Return a label widget with Hello Kivy
return Label(text="Hello Kivy")
helloKivy = HelloKivy()
helloKivy.run()
It says the module doesn't exist?
How do i find the path of this module (and other modules)?
my kivy simple hello world app is not closing I'm using raspberry pi B and I can't close it I must unplug my raspberry pi 5v adapter to close it
I'm using rasbian jessie
this is the very simple code
import kivy
from kivy.app import App
from kivy.uix.label import Label
class mamdouh(App):
def build(self):
return Label(text='mamdouh')
if __name__=='__main__':
mamdouh().run()
What I was trying to say in the comment was. That you need to have some action to cause the quit, as the run method will run in a loop indefinitely otherwise.
If you now click on the Button labeled 'paul' it will quit.
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
class mamdouh(App):
def build(self):
lbl = Label(text='paul')
btn = Button(text='mamdouh')
btn.bind(on_press=lambda b: app.stop())
lbl.add_widget(btn)
return lbl
if __name__ == '__main__':
app = mamdouh()
app.run()
I know nothing about kivy but I can see that this should allow you to quit, whether you want a Button in your app is another question.
Another way to kill it and avoid the reboot is simply to go back to the prompt where you launched your app and do CTRL + C. This will only work from the prompt though, not from the app window itself.