How to add an image to Kivy Python

Asked

Viewed 491 times

0

I need to add an image to my screen and was following what I was doing in all other widgets.

My code:

class MainApp(App):
    def build(self):
        layout1 = FloatLayout()
        button = Button(text='iniciar',
        pos_hint={'x':.375, 'y':.65}, size_hint=(.25, .05))
        textinput1 = TextInput(pos_hint={'x':.375, 'y':.55}, size_hint=(.25, .05))
        textinput2 = TextInput(pos_hint={'x':.375, 'y':.45}, size_hint=(.25, .05))
        textinput3 = TextInput(pos_hint={'x':.375, 'y':.35}, size_hint=(.25, .05))
        label1 = Label(text='Entrada:', pos_hint={'x':.375, 'y':.60}, size_hint=(.25, .05))
        label2 = Label(text='Saida:', pos_hint={'x':.375, 'y':.50}, size_hint=(.25, .05))
        label3 = Label(text='Objeto:',pos_hint={'x':.375, 'y':.40}, size_hint=(.25, .05))
        logo = Image(source='logoheader.png', pos_hint={'x':.375, 'y':.40})

        layout1.add_widget(button)
        layout1.add_widget(textinput1)
        layout1.add_widget(textinput2)
        layout1.add_widget(textinput3)
        layout1.add_widget(label1)
        layout1.add_widget(label2)
        layout1.add_widget(label3)
        layout1.add_widget(logo)

        return layout1


MainApp().run()

However when I try to run with the logo I am prevented with the following message:

logo = Image(source='logoheader.png', pos_hint={'x':.375, 'y':.40})
TypeError: __init__() missing 1 required positional argument: 'arg'

The code works perfectly when I comment on the logo line.

1 answer

0


I found the mistake,

Was importing:

 from kivy.core.image import Image

When it should really matter:

from kivy.uix.image import Image

Browser other questions tagged

You are not signed in. Login or sign up in order to post.