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
Related
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)`
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)
This code compile correctly.
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen
from kivy.uix.boxlayout import BoxLayout
from kivymd.uix.textfield import MDTextFieldRect
from kivy.lang import Builder
class App(MDApp):
def build(self):
self.screen = Screen()
return self.screen
def on_start(self):
l = BoxLayout()
self.screen.add_widget(l)
w = MDTextFieldRect()
l.add_widget(w)
App().run()
But If you just change the widget from MDTextFieldRect to MDTextFieldRound or MDTextField, the application will crash and I don't know why (there is no apparent error message).
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen
from kivy.uix.boxlayout import BoxLayout
from kivymd.uix.textfield import MDTextFieldRound
from kivy.lang import Builder
class App(MDApp):
def build(self):
self.screen = Screen()
return self.screen
def on_start(self):
l = BoxLayout()
self.screen.add_widget(l)
w = MDTextFieldRound()
l.add_widget(w)
App().run()
And to confuse me even more, it can work if you use the kv langage !!!
from kivymd.app import MDApp
from kivy.lang import Builder
KV = '''
Screen:
MDTextFieldRound:
icon_left: 'key-variant'
normal_color: app.theme_cls.accent_color
'''
class App(MDApp):
def build(self):
self.screen = Builder.load_string(KV)
return self.screen
App().run()
I'm working on a project with python and kivymd and i want to display an MDList in my file kv (list.kv)
but it doesn't work , i don't know where is the problem !! any suggestions
this is main.py
from kivy.lang import Builder
from mysql.connector import Error
from baseclass.start import Start
from kivy.lang import Builder
from threading import Thread
from kivy.uix.screenmanager import Screen
from kivy.utils import get_color_from_hex
from spin_load import ProgressSpinner
from kivymd.color_definitions import colors
from kivy.uix.recycleview import RecycleView
from kivy.core.window import Window
from kivy.uix.recycleview import RecycleView
import mysql.connector
from kivymd.uix.menu import MDDropdownMenu
from kivy.properties import OptionProperty
from kivy.properties import ObjectProperty
from kivymd.uix.bottomsheet import MDListBottomSheet
from kivymd.uix.expansionpanel import MDExpansionPanel
from kivymd.uix.boxlayout import BoxLayout
from kivymd.uix.list import OneLineListItem
Window.size = (360, 600)
class Codebarre(Screen):
def on_start(self):
for i in range(20):
self.root.ids.container.add_widget(
OneLineListItem(text=f"Single-line item {i}")
)
class MyApp(MDApp):
def build(self):
self.theme_cls.primary_palette = "DeepPurple"
return Builder.load_file("main.kv")
MyApp().run()
and this is the file where i want to display the MDList
list.kv
#:import utils kivy.utils
<Codebarre>:
name: 'codebarre'
ScrollView:
MDList:
id: container ```
It turns out that the on_start() method was never called. A working version of main.py is below. I didn't change list.kv.
from kivy.lang import Builder
from threading import Thread
import kivy.clock
from kivy.uix.screenmanager import Screen
from kivy.utils import get_color_from_hex
from kivymd.color_definitions import colors
from kivy.uix.recycleview import RecycleView
from kivy.core.window import Window
from kivy.uix.recycleview import RecycleView
from kivymd.uix.menu import MDDropdownMenu
from kivy.properties import OptionProperty
from kivy.properties import ObjectProperty
from kivymd.uix.bottomsheet import MDListBottomSheet
from kivymd.uix.expansionpanel import MDExpansionPanel
from kivymd.uix.boxlayout import BoxLayout
from kivymd.uix.list import OneLineListItem
from kivymd.app import MDApp
from kivy.uix.stacklayout import StackLayout
Window.size = (360, 600)
class Codebarre(Screen):
def __init__(self, **kvargs):
self.app = MDApp.get_running_app()
super().__init__(**kvargs)
kivy.clock.Clock.schedule_once(self.build)
def build(self, *args):
for i in range(20):
self.ids.container.add_widget(
OneLineListItem(text=f"Single-line item {i}")
)
class MyApp(MDApp):
def build(self):
self.theme_cls.primary_palette = "DeepPurple"
Builder.load_file("list.kv")
return Codebarre()
MyApp().run()
I wanted to trie out the anchor Layout unsing kivy language,but my Label was not affeckted by the AnchorLayout in any way
from kivy.app import App
from kivy.lang import Builder
from kivy.properties import ListProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.properties import NumericProperty
from kivy.properties import StringProperty
wurzel = Builder.load_string('''
AnchorLayout:
Label:
text: 'test'
anchor_x:'left'
anchor_y:'top'
''')
class TurF(App):
def build(self):
return wurzel
TurF().run()
The AnchorLayout is probably working fine, but your label fills it. Set something like the following instead.
AnchorLayout:
Label:
text: 'test'
anchor_x:'left'
anchor_y:'top'
size_hint: None, None
size: 50, 50