Kivy, make sometihing happen 1 sec after i press a button - python

I have tried for many hours, reading the wiki and experimenting in different ways but I have not been able to do it, can someone please explain to me explicitly (showing me) how to do this without only linking me to the wiki. Below you will find my code copied, where you read on_release: under the button with its id "settings", I want it to actually happen not on release but 1 sec after I have pressed the button.
.py file:
import kivy
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.config import Config
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
#title
#self.title('Past Paper Question Search 🔎')
#background
Window.clearcolor = (0.145, 0.145, 0.149, 1)
#resizability
Config.set('graphics', 'resizable', True)
class FloatLayout(FloatLayout):
def __init__(self, **kwargs):
super(FloatLayout, self).__init__(**kwargs)
class GUIApp(App):
def build(self):
return FloatLayout()
if __name__ == "__main__":
GUIApp().run()
.kv file:
<FloatLayout>:
BoxLayout:
id: searchBox
orientation: 'horizontal'
size_hint_x: 0.6
size_hint_y: 0.07
pos_hint: {"x":0.2, "y":0.7}
TextInput:
background_color: 0.275, 0.275, 0.275, 1
multiline: False
font_size: self.height/1.6
foreground_color: [1, 1, 1, 1]
hint_text: "Search"
hint_text_color: [1, 1, 1, 0.3]
cursor_color: [1, 1, 1, 1]
padding: [(self.height)/2-(self.line_height/2.0), (self.height)/2-(self.line_height/2.0), 6, 0]
Button:
size_hint_y: 1
width: self.height
size_hint_x: None
border: 0, 0, 0, 0
background_normal: "resources/Search.png"
background_down: "resources/Search_pressed.png"
Button:
id: settings
size_hint_y: 0.095
width: self.height
size_hint_x: None
border: 0, 0, 0, 0
background_normal: "resources/empty.png"
background_down: "resources/empty.png"
pos_hint: {"x":0.92, "y":0.9}
on_press: gif.anim_delay = 0.10
on_press: gif._coreimage.anim_reset(True)
on_release: settings.pos_hint= {"x":0.2, "y":2}
on_release: close.pos_hint= {"x":0.92, "y":0.9}
on_release: searchBox.pos_hint= {"x":0.2, "y":2.7}
Image:
id: gif
source: 'resources/settings_gif.gif'
center: self.parent.center
size: self.parent.size
anim_delay: -1
anim_loop: 1
allow_stretch: True
Button:
id: close
size_hint_y: 0.095
width: self.height
size_hint_x: None
border: 0, 0, 0, 0
background_normal: "resources/X.png"
background_down: "resources/X.png"
on_press: searchBox.pos_hint= {"x":0.2, "y":0.7}
on_press: settings.pos_hint= {"x":0.92, "y":0.9}
on_press: close.pos_hint= {"x":0.92, "y":2.9}
pos_hint: {"x":0.92, "y":2.9}
Thx in advance

Here is a small example. Read about Clock: https://kivy.org/doc/master/api-kivy.clock.html?highlight=clock#module-kivy.clock
from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock
kv = """
BoxLayout:
orientation: 'vertical'
Label:
id: status
Button:
size_hint_y: None
height: 48
text: 'Press'
on_release: app.schedule_action()
"""
class WaitOneSecondApp(App):
def build(self):
return Builder.load_string(kv)
def schedule_action(self):
self.root.ids.status.text = 'Waiting One Second...'
Clock.schedule_once(self.wait_over, 1)
def wait_over(self, dt):
self.root.ids.status.text = 'The wait is over'
WaitOneSecondApp().run()

Related

How to change widget on click to another widget - Python (Kivy)

Im new to Python and Kivy. But I want to create a mobile app. It is supposed to be an app that will have a menu with dishes. I want when clicking on an image with a specific food, the image with that food changes to another widget with text (what the food contains and allergens), when clicked again, the image returns. Thanks for answers! Vasa
IMAGE OF APP
from kivy.uix.button import Button
import kivy
kivy.require("1.9.1")
from kivy.app import App
from kivy.uix.scrollview import ScrollView
from kivy.core.window import Window
from kivy.app import runTouchApp
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import Screen
from kivy.uix.anchorlayout import AnchorLayout
from kivy.lang import Builder
from kivy.config import Config
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle, Color
from kivy.core.window import Window
from kivy.lang import Builder
Config.set('graphics', 'resizable', True)
class MainLayout(BoxLayout):
def spinner_clicked(self, value):
self.ids.tlac.text = value
class Home(App):
def build(self):
Window.clearcolor = (.92, .53, .58)
return MainLayout()
Home().run()
This is kv. file:
<MainLayout>:
orientation: "vertical"
AnchorLayout:
canvas:
Color:
rgba: .5, .1, .1, .1
Rectangle:
pos: self.pos
size: self.size
anchor_x: "center"
anchor_y: "top"
size_hint: 1, 0.2
BoxLayout:
orientation: "horizontal"
Image:
source:"logo.png"
Button:
background_color: .92, .53, .58, 0
pos_hint: {"center_x" : 0.5}
on_press: self.background_color = (.5, .1, .1, .2)
on_release: self.background_color = (.5, .1, .1, .0)
Image:
source:"logo_2.ico"
center_x: self.parent.center_x
center_y: self.parent.center_y
Spinner:
id: burger
background_color: .92, .53, .58, 0
pos_hint: {"center_x" : 0.5}
values: ["A", "B", "C"]
on_text: root.spinner_clicked(burger.text)
color: .92, .53, .58, 0
Image:
source:"menu.png"
center_x: self.parent.center_x
center_y: self.parent.center_y
ScrollView:
BoxLayout:
orientation: "vertical"
size_hint: 1, None
height: self.minimum_height
spacing: 5
GridLayout:
cols: 2
spacing: 5
size_hint: 1, None
height: self.minimum_height
BoxLayout:
height: 500
orientation: "vertical"
Button:
background_normal: 'obr.png'
background_down: 'down.png'
size_hint: .5, 1
pos_hint: {"x":.25, "y":1}
Button:
text: "kobliha \ncena"
halign: "center"
valign: "middle"
on_press: self.background_color = (.5, .1, .1, .1)
on_release: self.background_color = (.92, .53, .58, 0)
background_color: .92, .53, .58, 0
Button:
text: "koko2"
size_hint: 1, None
height: 500
Button:
text: "koko2"
size_hint: 1, None
height: 150
Button:
text: "koko3"
size_hint: 1, None
height: 150
Button:
text: "koko4"
size_hint: 1, None
height: 150
Button:
text: "koko5"
size_hint: 1, None
height: 150
Button:
text: "koko6"
size_hint: 1, None
height: 150
Button:
text: "koko7"
size_hint: 1, None
height: 150
Button:
text: "end"
size_hint: 1, None
height: 150
IMAGE OF APP

got dlopen error one Foundation: dlopen(/System/Library/Frameworks/foundation.framework/Versions/Current/Foundation,0x0001):(Kivy-iOS)

I’m new to kivy, trying to make kivy app with kivyiOS. the App has only very simple move. 1 screen has some buttoms and if you push one, move to next screen. Each buttom has pictures on its background.
It works perfectly on simulator, but can’t on iPhone8. It works as same as simulator, besides the background pictures of buttoms, they are vanished.
I can't understand why only pictures are gone. I've already tried:
clean build, change file names into no-CAPITAL style, replace the pictures into the same place as main.py, and so on.
Of couese I added AppIcon on xcodes.
Is there anything I can do? Please help me.
Python shows error below:
Got dlopen error one Foundation:
dlopen(/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation,0x0001): tried: …(no such file)
main.py
from kivy.config import Config
Config.set('graphics', 'width', '500')
Config.set('graphics', 'height', '500')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.image import Image
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.graphics.texture import Texture
from kivy.properties import NumericProperty
from kivy.core.text import LabelBase, DEFAULT_FONT
from kivy.resources import resource_add_path
resource_add_path("/System/Library/Fonts")
LabelBase.register(DEFAULT_FONT, "ヒラギノ角ゴシック W0.ttc")
presentation = Builder.load_file("main.kv")
class MenuScreen(Screen):
pass
class FeelingScreen(Screen):
pass
class TodoScreen(Screen):
pass
class BodyScreen(Screen):
pass
class YesnoScreen(Screen):
pass
class ToiletScreen(Screen):
pass
class AskScreen(Screen):
pass
class WantScreen(Screen):
pass
class ThisthatScreen(Screen):
pass
class mainApp(App):
def build(self):
sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(FeelingScreen(name='Feeling'))
sm.add_widget(TodoScreen(name='Todo'))
sm.add_widget(YesnoScreen(name='Yesno'))
sm.add_widget(BodyScreen(name='Body'))
sm.add_widget(ToiletScreen(name='Toilet'))
sm.add_widget(AskScreen(name="Ask"))
sm.add_widget(WantScreen(name="Want"))
sm.add_widget(ThisthatScreen(name="Thisthat"))
return sm
return presentation
def __init__(self, **kwargs):
super(mainApp, self).__init__(**kwargs)
self.title = "PODD_proto"
if __name__ == "__main__":
mainApp().run()
main.kv
<MenuScreen>:
canvas:
Rectangle:
pos: self.pos
size: self.size
GridLayout:
rows: 3
cols: 3
Button:
background_normal: "relative pass"
valign: "top"
color: 0, 1, 0, 1
font_size: "30"
bold: True
on_press: root.manager.current = 'Ask'
Button:
background_normal: "relative pass"
text_size: self.size
valign: "top"
color: 0, 1, 0, 1
font_size: "30"
bold: True
on_press: root.manager.current = 'Ask'
Button:
background_normal: "relative pass"
text_size: self.size
valign: "top"
color: 0, 1, 0, 1
font_size: "30"
bold: True
on_press: root.manager.current = 'Ask'
Button:
background_normal: "relative pass"
text_size: self.size
valign: "top"
color: 0, 1, 0, 1
font_size: "30"
bold: True
on_press: root.manager.current = 'Ask'
Button:
background_normal: "relative pass"
text_size: self.size
valign: "top"
color: 0, 1, 0, 1
font_size: "30"
bold: True
on_press: root.manager.current = 'Want'
Button:
background_normal: "relative pass"
text_size: self.size
valign: "top"
color: 0, 1, 0, 1
font_size: "30"
bold: True
on_press: root.manager.current = 'Yesno'
Button:
background_normal: "relative pass"
text_size: self.size
valign: "top"
color: 0, 1, 0, 1
font_size: "30"
bold: True
on_press: root.manager.current = 'Toilet'
Button:
background_normal: "relative pass"
text_size: self.size
valign: "top"
color: 0, 1, 0, 1
font_size: "30"
bold: True
on_press: root.manager.current = 'Feeling'
Button:
background_normal:"relative pass"
text_size: self.size
valign: "top"
color: 0, 1, 0, 1
font_size: "30"
bold: True
on_press: root.manager.current = 'Todo'
<AskScreen>:
(omitted)
<FeelingScreen>:
(omitted)
<TodoScreen>:
(omitted)
<YesnoScreen>:
(omitted)
<ToiletScreen>:
(omitted)
<WantScreen>:
(omitted)
<ThisthatScreen>:
(omitted)
Please help me. Thank you in advance.

Showing tasks only after new program launch. kivy

Good evening. I'm learning kivy and trying to make something like "microsoft to do". But I have a problem. Now I'm doing an adding task function. The main idea of it:
When I click "add task"(button with plus icon) button, my screen changes on "AddingNewTaskScreen".
In AddingNewTaskScreen class I created a function ""addTask that takes text from TextInput and add it in text file. Then it changes this screen on "MainMenuScreen"
In MainMenuScreen class(it is first screen), in constructor i call a "taskRead" function that takes text from text file and write it in array. Then it adds elements of arrays in MDList and after it, it adds this MDList to ScrollView.
And it works, but it takes shows me tasks after new programm launch. For example: I add the task and the "MainMenuScreen" doesn't show me anything. But when I restart my programm, everything are in ScrollView. If you have any ideas how it can be fixed, please tell me, I wold really apreciate it. Thank you for advance.
main.py
from kivy.uix.button import Button
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.core.window import Window
from kivy.uix.widget import Widget
from kivymd.app import MDApp
from kivymd.uix.list import OneLineListItem, MDList
from kivy.properties import ObjectProperty
from kivy.uix.scrollview import ScrollView
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
class MainMenuScreen(Screen):
listBox = ObjectProperty()
theme_changer = ObjectProperty()
search_task = ObjectProperty()
all_tasks = ObjectProperty()
important_tasks = ObjectProperty()
create_list = ObjectProperty()
completed_tasks = ObjectProperty()
list_name = ObjectProperty()
sort = ObjectProperty()
rename = ObjectProperty()
add_button = ObjectProperty()
scroll = ScrollView()
list_view = MDList()
def __init__(self, **kw):
super().__init__(**kw)
self.taskRead()
def taskRead(self):
sv = open('tasks.txt', 'r', encoding='utf-8')
arr = sv.read().split('\n')
sv.close()
for i in range(len(arr)):
self.list_view.add_widget(OneLineListItem(text=arr[i], on_press=self.scr))
self.add_widget(MDList())
self.scroll.add_widget(self.list_view)
self.listBox.add_widget(self.scroll)
def scr(self, value):
self.manager.transition = FadeTransition()
self.manager.current = 'goodbye_screen'
class ToDoListApp(MDApp):
def __init__(self, **kw):
super().__init__(**kw)
def build(self):
self.theme_cls.theme_style = "Dark"
Window.size = (1300, 700)
sm = ScreenManager()
sm.add_widget(MainMenuScreen(name='main_menu_screen'))
sm.add_widget(ImportantOrCompletedTaskCheckScreen(name='goodbye_screen'))
sm.add_widget(AddingNewTaskScreen(name='adding_newTask_screen'))
return sm
class AddingNewTaskScreen(Screen):
taskToTxt = ObjectProperty()
addTaskButton = ObjectProperty()
def __init__(self, **kw):
super().__init__(**kw)
def addTask(self):
task_text = str(self.taskToTxt.text)
sv = open('tasks.txt', 'a', encoding='utf-8')
sv.writelines(str(task_text) + '\n')
sv.close()
ToDoListApp.get_running_app().root.current = "main_menu_screen"
# Class for another problem
class ImportantOrCompletedTaskCheckScreen(Screen):
pass
if __name__ == '__main__':
ToDoListApp().run()
todolist.kv
<MainMenuScreen#Screen>:
listBox:listBox
rename:rename
search_task:search_task
theme_changer:theme_changer
all_tasks:all_tasks
important_tasks:important_tasks
create_list:create_list
completed_tasks:completed_tasks
list_name:list_name
sort:sort
#add_button:add_button
orientation: 'vertical'
# right lateral panel
BoxLayout:
BoxLayout:
size_hint: '0.3', '0.8'
pos_hint: {'y': 0.17}
orientation: 'vertical'
GridLayout:
cols: 1
rows: 9
MDRoundFlatButton:
id: theme_changer
size_hint: 0.5, 0.3
text: 'Light theme'
line_color: 1,1,1,1
elevation_normal: 0
on_press: root.change_theme()
BoxLayout:
size_hint: 1, 0.5
MDRoundFlatButton:
size_hint: 1, 0.7
text: 'All tasks'
line_color: 1,1,1,1
id: all_tasks
BoxLayout:
size_hint: 1, 0.08
MDRoundFlatButton:
size_hint: 1, 0.7
text: 'Important'
line_color: 1,1,1,1
id: important_tasks
BoxLayout:
size_hint: 1, 0.08
MDRoundFlatButton:
size_hint: 1, 0.7
text: '+ Create \nlist'
line_color: 1,1,1,1
id: create_list
BoxLayout:
size_hint: 1, 0.08
MDRoundFlatButton:
size_hint: 1, 0.7
text: 'Completed \ntasks'
line_color: 1,1,1,1
id: completed_tasks
# top panel
BoxLayout:
orientation: 'vertical'
AnchorLayout:
anchor_y: 'top'
size_hint: 1, 0.05
GridLayout:
size_hint: 1, 0.05
cols: 4
rows: 1
Label:
text: 'Name'
size_hint: 0.5, 0.05
id: list_name
MDTextField:
id:search_task
halign: 'center'
valign: 'center'
hint_text: 'Search'
size_hint: 1, None
line_color_normal: 0.15,0.15,0.15
MDRectangleFlatButton:
id: rename
text: 'Rename'
line_color: 1,1,1,1
MDRectangleFlatButton:
text: 'Sort'
line_color: 1,1,1,1
id: sort
# Center
BoxLayout:
orientation: 'vertical'
size_hint: 0.1, 0.1
MDFloatingActionButton:
icon: "plus"
md_bg_color: 'black'
on_press: root.manager.current = 'adding_newTask_screen'
BoxLayout:
orientation: 'vertical'
size_hint: 1,1
BoxLayout:
ScrollView:
line_color_normal: 1,1,0,1
id: listBox
# Screen for another problem
<ImportantOrCompletedTaskCheckScreen#Screen>:
name: 'goodbye_screen'
AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
BoxLayout:
orientation: 'vertical'
size_hint: 0.5, 0.25
GridLayout:
cols: 2
rows: 1
size_hint: 0.3, 0.25
pos_hint: {'x': 0.35}
MDSwitch:
size_hint: 0.3, 0.3
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
line_color: 1, 1, 1, 1
Label:
text: 'Important'
BoxLayout:
size_hint: 0, 0.5
GridLayout:
cols: 2
rows: 1
size_hint: 0.3, 0.25
pos_hint: {'x': 0.35}
MDSwitch:
text: 'Important'
size_hint: 0.3, 0.3
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
line_color: 1, 1, 1, 1
Label:
text: 'Completed'
AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
MDRoundFlatButton:
text: 'Continue'
size_hint: 1, 0.5
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
line_color: 1, 1, 1, 1
on_press: root.manager.current='main_menu_screen'
<AddingNewTaskScreen#Screen>:
taskToTxt:taskToTxt
AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
BoxLayout:
orientation: 'vertical'
size_hint: 0.5, 0.25
MDTextField:
id: taskToTxt
hint_text: 'Name of new task'
color: 'white'
halign: 'center'
valign: 'center'
size_hint: 1, None
multiline: False
AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
MDRoundFlatButton:
text: 'Add task'
id: addTaskButton
on_press: root.addTask()
size_hint: 1, 0.5
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
line_color: 1, 1, 1, 1
In addTask you should get access to main screen
main_screen = ToDoListApp.get_running_app().root.get_screen('main_menu_screen')
and then you can add task to list
main_screen.list_view.add_widget(OneLineListItem(text=task_text, on_press=main_screen.scr))
def addTask(self):
task_text = str(self.taskToTxt.text)
sv = open('tasks.txt', 'a', encoding='utf-8')
sv.writelines(str(task_text) + '\n')
sv.close()
main_screen = ToDoListApp.get_running_app().root.get_screen('main_menu_screen')
main_screen.list_view.add_widget(OneLineListItem(text=task_text, on_press=main_screen.scr))
ToDoListApp.get_running_app().root.current = "main_menu_screen"
BTW:
ScreenManager is a parent for every Screen so you could write shorter with self.parent.
Or you could use self.manager
main_screen = self.parent.get_screen('main_menu_screen')
#main_screen = self.manager.get_screen('main_menu_screen')
# ... code ...
self.parent.current = "main_menu_screen"
#self.manager.current = "main_menu_screen"
In MainMenuScreen you could also create function to add single task
class MainMenuScreen(Screen):
def add_task(self, text):
self.list_view.add_widget(OneLineListItem(text=text, on_press=self.scr))
and then you could write it simpler in addTask
main_screen = self.parent.get_screen('main_menu_screen')
main_screen.add_task(task_text)
and in taskRead you could reduce for-loop
for text in arr:
self.add_task(text)

KivyMD - Cannot Update TextField's text when used in DialogBox

I have used KivyMD to develop a Screen which displays the Parameter values (In a DialogBox) of specific Item (which I listed them as OnelinelistItem). I also want to make provision for the user to change the parameter values from the DialogBox. But apparently I cant update the parameter settings from the DialogBox. The DialogBox contains the Textfield. Can anyone help me to figure out the issue, by going through the code, and let me know, where I am doing it wrong?
TIA! :)
testingsetpointpage.py
'''
from kivy.config import Config
Config.set('kivy', 'keyboard_mode', 'systemanddock')
from kivy.uix.boxlayout import BoxLayout
from kivymd.app import MDApp
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import Screen
from kivymd.uix.dialog import MDDialog
from kivy.properties import ObjectProperty
from kivy.core.window import Window
from kivymd.uix.button import MDFlatButton
from kivy.properties import StringProperty
Window.size = (1024, 600)
The Builder is shown here:
KV = """
#:kivy 1.11.0
#:import MDDropdownMenu kivymd.uix.menu.MDDropdownMenu
#:import MDRaisedButton kivymd.uix.button.MDRaisedButton
ScreenManager:
MainScreen:
<MainScreen>:
name: 'mainscreen'
NavigationLayout:
ScreenManager:
Screen:
name: 'homemain'
BoxLayout:
orientation:"vertical"
halign:"center"
#DOWN TAB
MDBottomNavigation:
MDBottomNavigationItem:
name: 'setpoint'
text: 'Setpoints'
icon: 'network'
BoxLayout:
orientation: "vertical"
MDToolbar:
title: 'Setpoints'
pos_hint: {'center_x':0.5,'center_y':0.95}
right_action_items: [["wifi", lambda x: app.navigation_draw()]]
left_action_items: [["menu", lambda x: nav_drawer.toggle_nav_drawer()]]
elevation: 10
BoxLayout:
orientation:"vertical"
padding: 5
spacing: 5
MDLabel:
text: " Functions: "
halign:"left"
theme_text_color: "Custom"
text_color: 0, 0, 1, 1
size_hint_y: 0.15
canvas.before:
Color:
rgba: (211/255.0,211/255.0,211/255.0,1)
Rectangle:
size: self.size
pos: self.pos
SetpointContent:
#MAKE THE PARAMETER LIST
<SetpointContent>:
BoxLayout:
orientation: "vertical"
padding: 5
spacing: 5
ScrollView:
MDList:
OneLineListItem:
text: "51P: Phase Time Overcurrent"
on_press: root.show_51Pdata()
<Content51P>
alarmpick51p: alp51p
alarmdelay51p: ald51p
trippick51p: trp51p
invcurve51p: inp51p
orientation: "vertical"
size_hint_y: None
height: "200dp"
GridLayout:
rows: 4
cols: 2
spacing: 10
MDLabel:
text: "Alarm Pickup: "
halign: "center"
theme_text_color: "Custom"
text_color: 0, 0, 1, 1
size_hint_y: 0.15
size_hint_x: 0.4
width:100
MDTextFieldRect:
id: alp51p
text: root.text1
multiline: False
MDLabel:
text: "Alarm Delay: "
halign: "center"
theme_text_color: "Custom"
text_color: 0, 0, 1, 1
size_hint_y: 0.15
size_hint_x: 0.4
width:100
MDTextFieldRect:
id: ald51p
text: str(app.Aldelay51P)
multiline: False
MDLabel:
text: "Trip Pickup: "
halign: "center"
theme_text_color: "Custom"
text_color: 0, 0, 1, 1
size_hint_y: 0.15
size_hint_x: 0.4
width:100
MDTextFieldRect:
id: trp51p
text: str(app.Trpick51P)
multiline: False
MDLabel:
text: "Inverse Curve: "
halign: "center"
theme_text_color: "Custom"
text_color: 0, 0, 1, 1
size_hint_y: 0.15
size_hint_x: 0.4
width:100
MDTextFieldRect:
id: inp51p
text: str(app.InverseCurve)
multiline: False
#####
"""
and the Classes are defined here:
class Content51P(BoxLayout):
app=MDApp.get_running_app()
text1 = StringProperty("1")
alarmpick51p = ObjectProperty()
alarmdelay51p = ObjectProperty()
trippick51p = ObjectProperty()
invcurve51p = ObjectProperty()
class MainScreen(Screen):
class SetpointContent(Screen):
def show_51Pdata(self):
self.dialog = MDDialog(title="51P Parameters:",
type="custom",
content_cls=Content51P(),
buttons=[MDFlatButton(text='Close', on_release=self.close_dialog),
MDFlatButton(text='Update', on_release=self.update51P)]
)
self.dialog.auto_dismiss = False
self.dialog.open()
def update51P(self, obj):
duc = Content51P()
app = MDApp.get_running_app()
duc.text1 = duc.ids.alp51p.text
print(duc.text1)
app.Alpick51P = float(duc.text1)
print(app.Alpick51P)
def close_dialog(self, obj):
self.dialog.auto_dismiss = True
self.dialog.dismiss()
class MainApp(MDApp):
Alpick51P = ObjectProperty("5")
Aldelay51P = ObjectProperty("5")
Trpick51P = ObjectProperty("5")
InverseCurve = ObjectProperty("Very Inverse")
def build(self):
self.theme_cls.primary_palette = "Blue"
screen = Builder.load_string(KV)
return screen
def navigation_draw(self):
print("Navigation")
def on_start(self):
pass
if __name__ == '__main__':
MainApp().run()
'''
The outlook looks something like this. I want to update the four parameters as the user clicks on the Update button and be able to view the value, the next time I open the DialogBx.
In the kv rule, under <Content51P> for MDTextFieldRect textinputs add:
on_text: app.Alpick51P = self.text
on_text: app.Aldelay51P = self.text
on_text: app.Trpick51P = self.text
on_text: app.InverseCurve = self.text
The on_text method should go to respective MDTextFieldRect.
Update the update51P() function should be like below now:
def update51P(self, obj):
app = MDApp.get_running_app()
print(app.Alpick51P)
print(app.Aldelay51P)
print(app.Trpick51P)
print(app.InverseCurve)
This would now print the updated inputs from textinput fields.

MDLabels stacked in one place (one above another)

I've some problems with multiple MDLabels in BoxLayout (that is contains by AnchorLayout), so all the MDLabel objects are stacked in one place on the screen!
I dont know how to make them centered and grouped like a list (with spacing and e.g.)
Please, help me with solving that problem!
Thanks a lot and sorry for bad english.
There is my main.py
from kivy.app import App
from kivymd.theming import ThemeManager
from kivymd.label import MDLabel
from kivy.uix.screenmanager import Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.metrics import dp, sp, pt
def toast(text):
from kivymd.toast.kivytoast import toast
toast(text)
class MyScreen(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.menu_items = [
{
"viewclass": "MDMenuItem",
"text": "text%d" % i,
"callback": self.callback,
}
for i in range(1, 3)
]
self.menu_button = None
def change_variable(self, value):
print("\nvalue=", value)
self.VARIABLE = value
print("\tself.VARIABLE=", self.VARIABLE)
def callback(self, *args):
toast(args[0])
class MainApp(App):
title = "KivyMD MDDropdownMenu Demo"
theme_cls = ThemeManager()
def build(self):
return MyScreen()
if __name__ == "__main__":
MainApp().run()
And there is my main.kv file contains:
#:import MDDropdownMenu kivymd.menus.MDDropdownMenu
#:import MDRaisedButton kivymd.button.MDRaisedButton
#:import MDLabel kivymd.label.MDLabel
<MDMenuItem>:
on_release:
app.root.change_variable(self.text)
app.root.menu_button.text = self.text
<MyScreen>:
name: 'myscrn'
AnchorLayout:
anchor_y: 'center'
BoxLayout:
orientation: 'vertical'
size_hint: 0.1, 0.5
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
spacing: dp(10)
MDRaisedButton:
id: mainbutton
size_hint: None, None
size: 3 * dp(48), dp(48)
text: 'MDButton1'
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
opposite_colors: True
on_release:
root.menu_button = mainbutton
MDDropdownMenu(items=root.menu_items, width_mult=4).open(self)
MDRaisedButton:
id: secondbutton
size_hint: None, None
size: 3 * dp(48), dp(48)
text: 'MDButton2'
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
opposite_colors: True
on_release:
root.menu_button = secondbutton
MDDropdownMenu(items=root.menu_items, width_mult=4).open(self)
AnchorLayout:
anchor_y: 'top'
BoxLayout:
orientation: 'vertical'
size_hint: 0.95, 0.5
padding: [0, 0, 0, 0]
spacing: dp(5)
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
MDLabel:
font_size: dp(12)
text: '123'
MDLabel:
font_size: dp(22)
text: '456'
Woops, looks like a simple mistake. Your indentation on KV Lang is incorrect. You didn't nest your labels into BoxLayout correctly.
AnchorLayout:
anchor_y: 'top'
BoxLayout:
orientation: 'vertical'
size_hint: 0.95, 0.5
padding: [0, 0, 0, 0]
spacing: dp(5)
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
MDLabel:
font_size: dp(12)
text: '123'
MDLabel:
font_size: dp(22)
text: '456'"""

Categories