How you add the button depends on where you are…
For example:
class MyApp(App):
def on_start(self):
self.root.get_screen('menue').ids.gl.add_widget(Button(text='Test Button'))
In this example self is app, root is the root widget, a ScreenManger. The ScreenManager has a method, get_screen() that returns the Screen instance of the same name. ids access the ids dict on the selected screen.
In a different screen you could access the screen manager with the manager attribute
class AnotherScreenClass(Screen):
def add_button(self):
self.manager.get_screen('menue').ids.gl.add_widget(Button(text='Test Button'))
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b29778dd-3c87-48c4-aa39-e9be0e9a4799n%40googlegroups.com.
The kivy widgets are arranged in a tree. There can be only one root widget. The app class has a property root, the root widget. In your app that root widget is a Screenmanager. A kivy program can have only one root widget, but it can have many ScreenManagers.
What is this <screen name = 'menu'>? It looks and behaves differently from the other elements.
The ScreenManager method get_screen(‘screen_name’) takes the screen name as a parameter, and returns the Screen widget associated with that name. ScreenManagers are unique in that there are multiple screens that are at the same level of the widget tree, the name is used to select the screen.
PyCharm’s code completion is not perfect.
A Screen is a Screen, it inherits from a RelativeLayout.
From: Nobody999
Sent: Friday, May 21, 2021 7:44 AM
To: Kivy users support
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/548893d3-6af0-4902-b1e9-3e7b8f390e54n%40googlegroups.com.
I use Pycharm
Here are a few resource I hope you find helpful.
From: Nobody999
Sent: Saturday, May 22, 2021 12:16 AM
To: Kivy users support
Subject: Re: [kivy-users] How to access widgets in screens using ScreenManager?
I'm slowly starting to understand a little better how Kivy and Python work together. I am not a programmer, although I have always programmed a little for a long time. As a teenager I taught myself procedural programming (with Basic) - at that time object orientation was not yet widespread, there was no internet yet and I only had a finger-thick command reference, not even a programming textbook. ;-) I played around with cobol, C, C#, PHP and others later. I know the basic concepts of object orientation, but I have little experience with OO programming and even less with GUIs. But it's very exciting and Kivy is obviously very capable. Anyway, it's fun and I keep trying.
Thanks for your help.
By the way, which IDE would you recommend for python?
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/0ba7252a-8219-4c08-8278-59aff8b2c2f1n%40googlegroups.com.
I thought you resolved this issue. If this is still a problem, post a minimal runnable example.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/918eaca3-ad3b-4abf-9f1b-479eb84fcfc5n%40googlegroups.com.
In the screen_lista.py file, as part of a Screen (ScreenRecycleView) you want to access another screen that is under the ScreenManager that is the root widget.
In ScreenRecycleVIew, the attribute self.manager refers the screen_manager. This is because the ScreenRecycleView is instanced under that ScreenManager.
The ScreenManager you want to access is actually the root widget of the app. Get the app, and the root widget (screen_manager_login), then access the screen.
def on_double_tap(self, *args):
print("<on_double_tap> event")
app = MDApp.get_running_app()
print(app.root.get_screen('main_screen').ids)
From: Elias Coutinho
Sent: Wednesday, April 20, 2022 11:12 AM
To: kivy-...@googlegroups.com
Subject: Re: [kivy-users] How to access widgets in screens using ScreenManager?
Yes, I had solved it, but we entered the phase of refactoring the code and in this refactoring I separated the screens into files.
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8oUFHyYm24s6TdzUMZ3WnPBBtnyiFavHxPCudPu14vm-A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/626097e3.1c69fb81.22589.23c4SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
You want to add the touch behavior to your ImageCard. This is what you want the user to touch.
Inside ImageCard, self.source is the filename. In the appropriate touch routine, add the code below:
app = MDApp.get_running_app()
app.selected_image = self.source
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8rKP3spJFzqfDZ-an%2BPi3dtMW7nR6WuSFoBLmScEe3G7A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6260e969.1c69fb81.918fc.9b6cSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
There is something odd there with the TouchBehavior, the recycleview and the MDCard…
As a workaround, I added the touch behavior to the RecycleGridLayout and get the info from with widget on a double_tap.
from kivymd.app import MDApp
from kivy.properties import ListProperty
from kivy.properties import StringProperty
from kivy.properties import ObjectProperty
from kivy.uix.screenmanager import Screen
from kivymd.uix.card import MDCard
from kivymd.uix.behaviors import TouchBehavior
from kivy.uix.recyclegridlayout import RecycleGridLayout
from kivy.lang import Builder
from random import sample, choice
from string import ascii_lowercase
sample_images = [
"https://cdn.neemo.com.br/uploads/settings_webdelivery/logo/5591/No-Image.jpg",
"https://upload.wikimedia.org/wikipedia/commons/thumb/5/5f/SL_Bundala_NP_asv2020-01_img08.jpg/640px-SL_Bundala_NP_asv2020-01_img08.jpg",
"https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Palaeobranchiostoma_hamatotergum.jpg/482px-Palaeobranchiostoma_hamatotergum.jpg",
"https://upload.wikimedia.org/wikipedia/commons/thumb/a/ac/No_image_available.svg/1024px-No_image_available.svg.png",
]
## A T EN C A O o click para chamar a tela de imagem será aqui!
Builder.load_string("""
<ImageCard>
id: ec
size_hint: ('180dp', None)
ripple_behavior: True
source:''
text:''
orientation:'vertical'
FitImage:
pos_hint: {'center_x': .5, 'center_y': .25}
source: root.source
size_hint: None, None
width: dp(150)
height: dp(150)
#radius: [99, 99, 99, 99]
MDBoxLayout:
orientation:'horizontal'
MDLabel:
text:root.text
halign:"center"
#bold: True
<ScreenRecycleView>:
name: 'screen_listagem'
FloatLayout:
MDBoxLayout:
pos_hint: {'center_x': 0.5, 'center_y': 0.3}
RecycleView:
id: rv
data: root.image_data
viewclass: "ImageCard"
TouchRecycleGridLayout:
screen: root
cols: 2
default_size: dp(155), dp(200)
padding: dp(5) # Determina o espaçamento entre um widget e outro pelos lados
spacing: dp(5) # Determina o espaçamento entre um widget e outro de cima para baixo
#radius:dp(25)
# Tamanho do retangulo com a imagem e os textos
#default_size: dp(155), dp(75) # Determina o tamanho do widget (Largura, Altura)
default_size_hint: 1, None ##### Define a largura do widget sempre próximo as bordas
size_hint_y: None ##### Associado a default_size_hint
height: self.minimum_height
#ripple_behavior: True""")
class TouchRecycleGridLayout(TouchBehavior, RecycleGridLayout):
screen = ObjectProperty()
def on_double_tap(self, touch, *args):
i = self.get_view_index_at(touch.pos)
w = self.parent.view_adapter.views[i]
app = MDApp.get_running_app()
app.selected_image = w.source
self.screen.manager.current = 'tela_item'
class ImageCard(MDCard):
dialog = None
text = StringProperty()
source = StringProperty()
class ScreenRecycleView(Screen):
image_data = ListProperty()
def on_kv_post(self, base_widget):
self.ids.rv.data = [
{
'source': choice(sample_images),
'text': ''.join(sample(ascii_lowercase, 6))
}
for x in range(50)
]
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8pQ3E51dXgc087rWMNmq9tGBhW1yxp%2BLqmavB2RTB8zKA%40mail.gmail.com.
Here you go:
MDFloatingActionButton:
pos_hint: {'center_x': .9, 'center_y': .9}
icon: "arrow-left-bold"
elevation_normal: 12
on_release:
print('The problem button')
# root is the TelaItem screen instance. Each screen has a manager...
# this is the screen manager with the id screen_manager.
root.manager.direction = 'right'
root.manager.current = 'screen_listagem'
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CALgom8popujLoTw4gPtvvgSEzQXf4%3DhfdZxVSN3COxwQ0f4Ocw%40mail.gmail.com.
Elliot Garbus, All right, working! I'm going to open a documentation to leave these tips saved. |
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6261e2ae.1c69fb81.e1178.9071SMTPIN_ADDED_MISSING%40gmr-mx.google.com.