button image works individually but not when added to other part of the program

37 views
Skip to first unread message

Arash GM

unread,
Jun 1, 2016, 7:08:04 AM6/1/16
to Kivy users support
hello guys,
I hope you are well,
so the problem I have is:
I have 2 lists of buttonImages. each work when I run the individual modules and give me to separate list of button images as shown below:

1st list:

2nd list:

, but when I add those list of buttonImages to a GrideLayout(cols = 2), this happens:


I am sure the buttons exist because when i click on that white area i get feedback on terminal. it is also interesting that I realized only the last added button is shown as you see in the picture, moreover, half of those buttons is under white space but the image is not.
my code for making sldermenu was:
#!python
import kivy
kivy
.require('1.5.1')
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.stacklayout import StackLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.scrollview import ScrollView
from kivy.uix.slider import Slider
from functools import partial
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder


kation
= None
def getkation():
       
return kation.ids.i.source
       
Builder.load_string("""
<ButtonsApp>:
    orientation: "
vertical"
    Button:
        border:  (0,0,0,0)
        id: b
        on_press: root.select()
        Image:
            id: i
            source:
            size: 750, 750
            allow_stretch: True
            center_x: self.parent.center_x
            center_y: self.parent.center_y
"""
)

class ButtonsApp(App, BoxLayout):
   
def build(self):
       
return self
       
   
def select(self):
       
global kation
       
if kation == None:
                kation
= self
       
else:
                kation
.ids.b.background_color = (1,1,1,1)
                kation
= self
       
self.ids.b.background_color = (0,1,0,1)
       
print(kation.ids.i.source)



class kationApp(App):

   
def build(self):
       
return self.layout
       
   
def make(self):


       
#this layout is the child widget for the main popup
        layout1
= StackLayout(orientation='lr-bt')

       
#this button is a child of layout1
       
#closebutton = Button(text='close', size_hint=(0.9,0.05))
       
#closebutton.bind(on_press=popup.dismiss)

       
#another child of layout1 and this is the scrollview which will have a custom draggable scrollbar
        scrlv
= ScrollView(size_hint=(0.9,0.95))

       
#the last child of layout1 and this will act as the draggable scrollbar
        s
= Slider(min=0, max=1, value=25, orientation='vertical', step=0.01, size_hint=(0.1, 0.95))

        scrlv
.bind(scroll_y=partial(self.slider_change, s))

       
#what this does is, whenever the slider is dragged, it scrolls the previously added scrollview by the same amount the slider is dragged
        s
.bind(value=partial(self.scroll_change, scrlv))

        layout2
= GridLayout(cols=1, size_hint_y=None)
        layout2
.bind(minimum_height=layout2.setter('height'))
       
       
#find anions
        f
= open('klst', mode = 'r')
        f
= f.read().strip().split()
       
       
for i in f:
            btn
= ButtonsApp(size_hint_y=None,  height=200, valign='middle', halign='middle')
            btn
.ids.i.source = './kpng/{}'.format(i)
            layout2
.add_widget(btn)
           
           
        scrlv
.add_widget(layout2)
       
#layout1.add_widget(closebutton)
        layout1
.add_widget(scrlv)
        layout1
.add_widget(s)
       
'''title = Button(text = '[b][i]Choose a Kation:[/b][/i]',
                       font_size = 15,
                       markup = True)
        print(title.text)
       
        layout1.add_widget(title)'''

       
#bl = BoxLayout( )
       
#bl.add_widget(layout1)
       
self.layout = layout1
       

       
   
def scroll_change(self, scrlv, instance, value):
        scrlv
.scroll_y = value

   
def slider_change(self, s, instance, value):
       
if value >= 0:
       
#this to avoid 'maximum recursion depth exceeded' error
            s
.value=value
           
if __name__ == '__main__':
    a
= kationApp()
    a
.make()
    a
.run()

thank you all for ur help.
Auto Generated Inline Image 1
Auto Generated Inline Image 2
Auto Generated Inline Image 3

ZenCODE

unread,
Jun 21, 2016, 4:14:43 PM6/21/16
to Kivy users support
Greetings

Can't run it as there is a file missing.


    f = open('klst', mode = 'r')

But I notice you have two App classes. That is not correct. Try changing

    class ButtonsApp(App, BoxLayout):

to

    class ButtonsBox(BoxLayout):

Otherwise, post the klst file.

Peace out
Reply all
Reply to author
Forward
0 new messages