When I run my kivy script,script runs without errors but I see no open window only a kivy icon in the task bar and it is not possible to open window.
This is a screenshot
This my code
from kivy.app import App
from kivy.uix.label import Label
class Test(App):
def build(self):
return Label(text='Hello
World',halign='center')
if __name__=='__main__':
Test().run()
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
I'm using Kivy 1.11.1 on Python 3.7, Ubuntu 20.04.
When I run my program my code shows a window, but the window is completely black and does not respond to any input.
My code is like this:
import kivy
kivy.require('1.11.1')
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout
from kivy.core.window import Window
Window.clearcolor = (0.3961, 0.4627, 0.8, 1)
class LoginScreen(GridLayout):
def btn1Click(self, instance):
print('The button was clicked')
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.cols = 2
self.button1 = Button(text='Click Me', font_size=14)
self.button1.bind(on_press=self.btn1Click)
self.add_widget(self.button1)
self.add_widget(TextInput())
class CreateMachineProgram(App):
def build(self):
return LoginScreen()
if __name__ == '__main__':
CreateMachineProgram().run()
When I comment out the line self.add_widget(TextInput()), all of a sudden my code loads properly. What am I doing wrong?
I implemented pywebview on kivy. After clicking the button it will create the window, but after closing the window and click the button again, the window did not created.
How can I solve this problem ?
Below is my code :
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
import threading
import webview
class LoginScreen(BoxLayout):
def __init__(self, **kwargs):
super(LoginScreen, self).__init__(**kwargs)
self.btn1 = self.add_widget(Button(text='Web',on_press=self.on_web))
def on_web(self,instance):
url='http://www.google.com'
print("Im open windows")
webview.create_window('My Web App', url=url,debug=True)
class MyApp(App):
def build(self):
return LoginScreen()
if __name__ == '__main__':
MyApp().run()
In the following lines, remove the debug=True from the webview.create_window. Then add webview.start(debug=True) per https://github.com/r0x0r/pywebview and https://pywebview.flowrl.com/examples/debug.html
webview.create_window('My Web App', url=url)
webview.start(debug=True)
Also, the following are the params for the create_window function, notice that there is no debug per https://pypi.org/project/pywebview/0.5/:
webview.create_window(title, url, width=800, height=600, resizable=True, fullscreen=False)
The above works for me (Python 3, Kivy 1.11, Windows10) after the edit and test of your code.
I have simple code for kivy, on W10 runs without problem. It falls down during loading in kivy launcher. Problem is without message.
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
class View(BoxLayout):
def __init__(self):
super().__init__()
self.text = "No text"
but = Button(text = "Press",on_press = self.show)
self.add_widget(but)
self.lbl = Label()
self.add_widget(self.lbl)
def show(self,obj):
self.lbl.text = self.text
pass
class MyPaintApp(App):
def build(self):
return View()
if __name__ == '__main__':
MyPaintApp().run()
It does not run because you call super wrong.
As kivy launcher uses python 2, you need to pass your class (View) and the instance (self) to super.
You need to edit your class like this:
class View(BoxLayout):
def __init__(self,**kwargs):
super(View,self).__init__(**kwargs)
in every failure in kivy launcher, there is a '.kivy/log' directory inside the project directory that has a full log. you could find all the problem there.