S
S
Stas Povalyaev2021-12-31 13:10:21
Python
Stas Povalyaev, 2021-12-31 13:10:21

How to make a background image in python kivy?

Hello! I have a problem, there is such a clicker:

the code

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.label import Label

class MainApp(App):
    i = 0
    def build(self):
        main_layout = BoxLayout()
        self.label = Label(text = "", size_hint = (.7, .9), pos_hint = {'center_x': 0.5, 'center_y': 0.7})
        btn = Button(text = "Clicks", size_hint = (.1, .1), pos_hint = {'top_x': 0.5, 'top_y': 1})
        btn.bind(on_press=self.on_button_press)
        main_layout.add_widget(self.label)
        main_layout.add_widget(btn)
        return main_layout

    def on_button_press(self, instance):
        self.i += 1
        self.label.text = "Clicked " + str(self.i + 1)
        
            

if __name__ == '__main__':
    app = MainApp()
    app.run()



but when i add background image:
fon_img = Image(source='fon1280x720.png')
 main_layout.add_widget(fon_img)


then it gives me this error:
TypeError: __init__() missing 1 required positional argument: 'imgtype'


what is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Chegevara_kyc, 2021-01-01
@cout_HelloWorld_andl

FloatLayout:   #Общий
        id:fl1
        orientation: 'vertical'
        canvas:
            Rectangle:
                source: 'Fon.jpg'
                size: self.size
                pos: self.pos
        #rows: 6

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question