filechooser in kivy without class - python

hi there i new in kivy iam learning without classes i want filechooser but any one tell me kivy filechooserIconView without class and not with kivy file only python file
from kivy.uix.button import Button
from kivy.app import runTouchApp
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.image import Image
from kivy.uix.gridlayout import GridLayout
from kivy.clock import Clock
from kivy.core.window import Window
from kivy.uix.scrollview import ScrollView
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
from kivy.uix.filechooser import FileChooserIconView
a=GridLayout(cols=1)
def a1():
global b
global c
c.text=str(b.path)
b=FileChooserIconView(path='/storage/emulated/0/')
from functools import partial
c=Button(text='ok')
a.add_widget(c)
b.bind(on_release=a1)
a.add_widget(b)
runTouchApp(a)

Your code almost works, just a couple issues. First, you are binding on_release to the FileChooser, but I think you want that bound to the Button. Second, our a1() method must accept an argument (the button). Here is a modified version of your code with those changes:
from kivy.uix.button import Button
from kivy.app import runTouchApp
from kivy.uix.gridlayout import GridLayout
from kivy.uix.filechooser import FileChooserIconView
a=GridLayout(cols=1)
def a1(button): # handle required arg
global b
global c
c.text=str(b.path)
b=FileChooserIconView(path='/home/jra')
c=Button(text='ok')
a.add_widget(c)
c.bind(on_release=a1) # bind to button, not FileChooser
a.add_widget(b)
runTouchApp(a)

Related

How do I bind the on_press function to the button in my kv app using the python file

I have tried to create a layout with multiple rows, where you can count up and down. The count is displayed in the label next to the buttons.
It is a part of a larger layout and application.
I get the layout that I want, but nothing happens when I press the buttons.
I have watched a lot of videos and searched the internet and encountered the .bind but I still haven't fixed it. I have also tried to make changes in the 'def add' and 'def sub'. I am not sure the *args should be there, but if i remove it I get a Traceback: TypeError: Countdown.add() takes 1 positional argument but 2 were given
I hope you can help on my way :)
The python file:
from kivy.app import App
from kivy.core.window import Window
from kivy.graphics.context_instructions import Color
from kivy.graphics.vertex_instructions import Ellipse, Line, Rectangle
from kivy.metrics import dp
from kivy.uix.scrollview import ScrollView
from kivy.properties import (BooleanProperty, NumericProperty, ObjectProperty,
StringProperty)
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.image import Image
from kivy.uix.label import Label
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.uix.stacklayout import StackLayout
from kivy.uix.textinput import TextInput
from kivy.uix.widget import Widget
Window.clearcolor =(1,1,1,1)
class Countdown(GridLayout):
my_text = StringProperty("0")
count = 0
def __init__(self, **kwargs):
super().__init__(**kwargs)
for i in range(0,10):
self.cols = 3
self.btn1=Button(text="+")
self.btn1.bind(on_press=self.add)
self.add_widget(self.btn1)
self.btn2=Button(text="-")
self.btn2.bind(on_press=self.sub)
self.add_widget(self.btn2)
self.lb=Label(text=self.my_text, color=[0,0,0,1])
self.add_widget(self.lb)
def add(self,*args):
self.count +=1
self.my_text = str(self.count)
def sub(self, *args):
self.count -=1
self.my_text = str(self.count)`

Fps bar on Kivy apps not disabling on mac os

I used Config.set('modules', 'monitor', '') on one of my Kivy apps to get the fps bar, but I can't get it disabled now.
Kivy version -- 1.10.1
I've tried everything and checked every line of code but can't get it disabled. Also if I write a basic code with just
from kivy.app import App
from kivy.uix.button import Button
imports I still getting the fps bar. I even reinstalled the whole Kivy environment but still I have the fps bar.
These are all the imports that I used in my file which created all the problem.
import kivy
kivy.require("1.10.1")
# from kivy.config import Config
# Config.set('graphics', 'resizable', 0)
# Config.set('graphics', 'width', 500)
# Config.set('graphics', 'height', 300)
# Config.set('modules', 'monitor', '')
from kivy.metrics import *
from kivy.core.window import Window
Window.size = (sp(500), sp(300))
from kivy.app import App
from kivy.uix.label import Label
from kivy.graphics import Line, InstructionGroup, Color
from kivy.properties import ObjectProperty, Property
from kivy.core.audio import SoundLoader
from kivy.clock import Clock
from kivy.uix.screenmanager import Screen, ScreenManager, FadeTransition
from kivy.lang import Builder
import random as rnd
import time
This is the basic code.
from kivy.app import App
from kivy.uix.button import Button
class TestApp(App):
def build(self):
return Button(text='Hello World')
TestApp().run()
Output Image
From eyllanesc's comment I've found a fix to this problem in case anyone else gets into the same problem.
Note: Always create a backup of the file.
Go to this directory.
Windows: C:\Users\tito\.kivy\config.ini
macOS: /Users/tito/.kivy/config.ini
Linux: /home/tito/.kivy/config.ini
Open config.ini
Find
[modules]
monitor =
Delete monitor = and Save it.
If anything happens just delete the config.ini and Kivy will create a new one but all your configurations will reset.

Kivy Text Editor Input Not Showing Up

I have unfortuanlly have encourtered an error in kivy and Python 3. I have not found a soultion via Google. I wanted to get text input at the very least but it does not show up. Just the text itself. Thank you for your time!
import kivy
kivy.require('1.10.1') # replace with your current kivy version !
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
class ColdKivyApp(App):
def build(self):
f = FloatLayout()
label = Label(text="Cold") #I acutally orginally called it Zone unitil I changed it into Cold cause it's really cold now
f.add_widget(label)
txt = TextInput(text='', focus=True, multiline=True, cursor_blink=True, background_color=(1,1,1,1))
f.add_widget(txt)
return f
if __name__ == '__main__':
ColdKivyApp().run()
It seems that there is a bug in TextInput when setting the focus in the constructor, a workaround is to set the focus an instant after the window is shown through Clock:
import kivy
kivy.require('1.10.1') # replace with your current kivy version !
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
from kivy.clock import Clock
class ColdKivyApp(App):
def build(self):
f = FloatLayout()
label = Label(text="Cold")
f.add_widget(label)
txt = TextInput(multiline=True, cursor_blink=True, background_color=(1,1,1,1))
f.add_widget(txt)
Clock.schedule_once(lambda *args: setattr(txt, "focus", True))
return f
if __name__ == '__main__':
ColdKivyApp().run()

How to simplify imports in Kivy

My starting code often looked like this:
import libs.apa_database
import inspect
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.scrollview import ScrollView
from kivy.properties import ObjectProperty, StringProperty, Property
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.uix.dropdown import DropDown
from kivy.uix.button import Button
from kivy.clock import Clock
So, I wondered if there were a way to reduce the clutter like this:
from system_assets import APADatabase, App, Clock
from layout_assets import App, BoxLayout, GridLayout, ScrollView
from screen_assets import ScreenManager, Screen, FadeTransition
from interface_assets import DropDow, Button,
The answer is "yes":
Create new Python files as a "folder" to hold your imports
Add the import statements to that Python file
Import the assets from that file
(Will update this Q with more detail when I have time.)

adding another screen in kivy

i am currently creating an android app that uses the kivy framework and a package from kivy garden. i want to add another screen in it but i cant. thank you
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.properties import ListProperty,ObjectProperty,NumericProperty
from kivy.uix.gridlayout import GridLayout
from kivy.uix.behaviors import ButtonBehavior
from kivy.metrics import dp
from material.flatui.flatui import FloatingAction,RaisedButton,_MaterialButton
from garden import *
from sqlalchemy import *
from kivy.core.text import LabelBase
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
class MyTab(GridLayout, AndroidTabsBase):
pass
class MyTabb(FloatLayout,AndroidTabsBase):
thoughts = ObjectProperty()
class MyTabbb(FloatLayout,AndroidTabsBase):
pass
class MyScreenManager(ScreenManager,Screen):
pass
class ShoppingScreen(Screen):
pass
class ExampleApp(App):
thoughts = ObjectProperty()
def build(self):
android_tabs = AndroidTabs()
return android_tabs
if __name__=='__main__':
from kivy.core.window import Window
from kivy.utils import get_color_from_hex
LabelBase.register(name='Modern Pictograms',
fn_regular='modernpics.ttf')
LabelBase.register(name='Heydings',
fn_regular='heydings.ttf')
LabelBase.register(name='Roboto',
fn_regular='Roboto-Thin.ttf')
Window.clearcolor = get_color_from_hex('#008CD4')
ExampleApp().run()
and the code in the kv lang
<FBut#Button>:
font_size: 100
font_name: 'modernpics'
<AndroidTabs>:
tab_indicator_height: '2dp'
anim_threshold: 0
MyTab:
orientation: 'horizontal'
cols: 2
spacing: 5
text: 'BUDGET'
FBut:
text: 'i'
so i want to add another screen to enable me view other widgets

Categories

Resources