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.
Related
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
I'm trying to change icon from kivy default one to some ico/png file that i provide
But it seems to be not working
I get this
Code:
from kivymd.app import MDApp
from kivy.lang import Builder
KV="""
Button:
text:""
"""
class Main(MDApp):
def build (self):
self.icon="image.png"
return Builder.load_string(KV)
Main().run()
Update:
Fixed the problem by changing the png,
But it still shows kivy logo for the loading screen ,is there any fix for this.???
My os is windows10 Chinese version. for input Chinese charactor, I use an IME to select word, like this:
but on a Kivy application, the Textinput widget can not activate IME select panel. for example, when i run the login demo from Kivy:
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
class LoginScreen(GridLayout):
def __init__(self, **kwargs):
super(LoginScreen, self).__init__(**kwargs)
self.cols = 2
self.add_widget(Label(text='User Name'))
self.username = TextInput(multiline=False)
self.add_widget(self.username)
self.add_widget(Label(text='password'))
self.password = TextInput(password=True, multiline=False)
self.add_widget(self.password)
class MyApp(App):
def build(self):
return LoginScreen()
if __name__ == '__main__':
MyApp().run()
The app screen is:
No IME select panel popup. What i expect is:
I searched doc from Kivy homepage, all IME related pages are about mobile device, not windows.
Please help.
Finally, i change the source code of SDL2, and compile a new dll to fix it. sure it's not a good solution, but the only i've found.
download SDL2 source code here: libsdl.org
find a file named "SDL_windowskeyboard.c", open it, add a macro definition:
rebuild it, make sure choose the correct platform(win32 or x64), then copy generated dll to overwrite the original one. In my project, the sdl package is in venv envirement "venv\share\sdl2\bin"
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.
So, I can run kivy example files (like pong) on my Android but I can't run my own app, it just saying "Hello World!".
I don't understand, if someone can help me.
This is my Python code :
import kivy
from kivy.app import App
from kivy.config import Config
from kivy.uix.label import Label
from kivy.uix.widget import Widget
Config.set('graphics','width','360')
Config.set('graphics','height','640')
class Mot(Widget):
def mot(self):
test = 0
def bouger(self):
class WorDown(App):
def build(self):
return Mot()
if __name__ == '__main__':
WorDown().run()
Next my Kivy code :
#:kivy 1.0
<Mot>:
Widget:
canvas:
Color:
rgb: (255, 0, 0)
Rectangle:
size: (360,640)
pos: self.pos
Label:
text: 'WorDown'
center_x: root.width / 2
And my android.txt :
title=WorDown
author=pito
orientation=portrait
So I put these three files in a folder in the Kivy folder of my Android Phone. And when I run Kivy launcher, and click on "WorDown", Kivy Launcher runs the app but crashes just 3 seconds after...
And I don't understand why, because on my Windows Computer, it runs very well!
Please look at the python code you included. In class Mot you have
def bouger(self):
but nothing in the function body.
Do you really don't have anything in the body? Your code shouldn't even run on your computer then, so I guess you just didn't post everything.
If you are sure that the code in this function is not causing the crash, just write "pass" in the function body, so that it doesn't confuse other readers.
you could follow the code
main.py
import kivy
from kivy.uix.label import Label
from kivy.app import App
class MyApp(App):
def build(self):
return Label(text='WorDown' )
if __name__=="__main__":
MyApp().run()
Try to run your code after removing 7 and 8 lines of your code.