Python - Modules not working - python

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)?

Related

Python Kivy window resize is jittery

Hey there i am new to kivy and am using Python 3.8.10 and Kivy version: 2.1.0
i am trying to get the window resize working and pulled this working example.
I am on ElementaryOS
When i run the following code and resize the window, it jumps around the screen towards the left bottom corner and is super jittery, when resizing to full screen the content is not staying center but moving to the left bottom corner...
# To change the kivy default settings
# we use this module config
from kivy.config import Config
# 0 being off 1 being on as in true / false
# you can use 0 or 1 && True or False
Config.set('graphics', 'resizable', True)
# import kivy module
import kivy
# this restrict the kivy version i.e
# below this kivy version you cannot use the app
kivy.require("1.9.1")
# base Class of your App inherits from the App class.
# app:always refers to the instance of your application
from kivy.app import App
# if you not import label and use it through error
from kivy.uix.label import Label
# defining the App class
class MyLabelApp(App):
def build(self):
# label display the text on screen
# markup text with different colour
l2 = Label(text ="[color = ff3333][b]Hello !!!!!!!!!!![/b] [color]\n [color = 3333ff]GFG !!:):):):)[/color]",
font_size ='20sp', markup = True)
return l2
# creating the object
label = MyLabelApp()
# run the window
label.run()

What module/s can I use to open a pdf with python that works after I converted it to an apk?

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()

Python 3 kivy ubuntu

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

How to Bind on_press to GridLayout in kivy python

i was trying to bind on_press method to gridLayout in kv language but i got this error AttributeError: pressed. I did some research even in the kivy doc but no help .So if any one has a solution to this problem please you may be a good resource
here is my testApp.py
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
class screendb(BoxLayout):
def mycall_back(self):
print('hello')
class testApp(App):
def build(self):
return screendb()
if __name__=='__main__':
testApp().run()
here is my testApp.kv
<Screendb#BoxLayout>:
GridLayout:
on_pressed:root.Mycall_back()
In your py file:
# Behaviors let you add behavior from one widget to another widget
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.gridlayout import GridLayout
# We create a new widget that is a GridLayout with access to Button Behaviors
# Like Button's 'on_press' method
class ButtonGrid(ButtonBehavior, GridLayout):
pass
class screendb(BoxLayout):
def mycall_back(self):
print('hello')
class testApp(App):
def build(self):
return screendb()
In your kv file:
# We create a Root Widget for the ButtonGrid
<ButtonGrid>:
<Screendb#BoxLayout>:
# We add an instance of the ButtonGrid class to our main layout
ButtonGrid:
# We can now use on_press because it is a part of the ButtonBehavior class, that makes up your ButtonGrid class.
on_press:root.mycall_back()
Note: There were a few minor mistakes in your post as well. For example, there is no method 'on_pressed', only 'on_press', you also wrote your callback as 'mycall_back' in your py file while writing it as 'Mycall_back' in your kv file, which refers to a different method that exists. Make sure your letter cases match.
video example

Kivy: Kivy launcher fall down

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.

Categories