Python Forum
Placing image button on top of background image
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Placing image button on top of background image
#1
Hello there Forum Members...
I have been developing in VBA for 10 years...My first time delving into python...Total Newbie...
The reason for me doing this is the need to convert my VBA Windows Operating App I developed - see below demo - into an Android App...

I'm trusting this can be done...
demo

I have just started...
I am wanting to add images as buttons to an already existing background image being the main screen...
Making use of Kivy & kv file


class EzImage(BoxLayout):
    pass
class ToTSlider(App):
    def build(self):  
        #return Builder.load_string('ToTSlider.kv')     
        return EzImage()  

# kv file
<EzImage>:
    BoxLayout:        
        Rectangle:
            source: 'Images\main.png'
            size: root.width, root.height
            pos: self.pos
        # Here I am wanting to add a button on top of main image
        Button:
            source: 'Images\launch.png' 
            size: root.width, root.height
            pos: self.pos      
Edit...I tried another approach...Also not working...
class BackGround(BoxLayout):
    pass

class ToTSlider(App):
    def build(self): 
        # This snippet adds my 3 required buttons...  
        EzImage = BoxLayout(orientation='horizontal')  
        btn1 = Image(source='Images\launch.png')
        btn2 = Image(source='Images\print.png')
        btn3 = Image(source='Images\leave.png')       
        EzImage.add_widget(btn1)
        EzImage.add_widget(btn2)
        EzImage.add_widget(btn3)
        # Cannot get background in...it is either or...
        return BackGround()
        return EzImage
# kv file code
<BackGround>:
    BoxLayout:
        canvas.before
            Rectangle:            
                size:self.size
                pos: self.pos
                source: 'Images\main.png'


Can I please get direction...Google has rendered no results...
Reply
#2
So...I played around today and finally got this figured out...
Step 1 down...Lotsa steps to go...
Home = """
<EzHomeScreen>:
    canvas.before:
        Rectangle:
            pos: self.pos
            size: self.size
            source: 'Images\main.png'                
    FloatLayout:
        Button:
            background_color: 0, 0 ,0, 0
            size_hint: .32, .046         
            on_press: root.leave() 
            pos_hint: {'center_x': 0.18, 'center_y': 0.165}   
            Image:
                source: "Images\leave.png"
                center_x: self.parent.center_x
                center_y: self.parent.center_y
        Button:
            background_color: 0, 0 ,0, 0
            size_hint: .32, .046         
            on_press: root.print() 
            pos_hint: {'center_x': 0.50, 'center_y': 0.165}   
            Image:
                source: "Images\print.png"
                center_x: self.parent.center_x
                center_y: self.parent.center_y
        Button:
            background_color: 0, 0 ,0, 0
            size_hint: .32, .046         
            on_press: root.launch() 
            pos_hint: {'center_x': 0.82, 'center_y': 0.165}   
            Image:
                source: "Images\launch.png"
                center_x: self.parent.center_x
                center_y: self.parent.center_y
"""

Builder.load_string(Home)

class EzHomeScreen(Screen):
    def leave(self):
        print('leave pressed')  
    def leave(self):
        print('print pressed') 
    def leave(self):
        print('launch pressed')
pass


sm = ScreenManager(transition=FadeTransition())
sm.add_widget(EzHomeScreen(name='EzHome'))


class ToTSlider(App):
    def build(self):
        return sm
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  image does not show with pillow Mohamad_afeff_nasser 5 1,294 Apr-13-2025, 07:53 PM
Last Post: snippsat
  Problem When using canny edge detection,black image returned rickyw2777 1 456 Feb-17-2025, 03:22 AM
Last Post: rickyw2777
  Why it gives me a black image and libpng warning: iCCP rickyw2777 1 462 Feb-16-2025, 08:26 PM
Last Post: rickyw2777
  QR code creation with image Raja31 1 819 Jan-15-2025, 11:17 AM
Last Post: Larz60+
Photo image generation with text style Belialhun 0 653 Oct-08-2024, 01:53 PM
Last Post: Belialhun
  Product Image Download Help Required pythonustasi 5 1,352 Jul-21-2024, 08:12 PM
Last Post: snippsat
  tkinter photo image problem jacksfrustration 5 3,518 Jun-27-2024, 12:06 AM
Last Post: AdamHensley
Photo image error pyc0de 2 1,805 Mar-23-2024, 06:20 PM
Last Post: pyc0de
  Using OpenCV and image path is invalid AudunNilsen 5 1,984 Mar-18-2024, 05:28 PM
Last Post: snippsat
  Count image's colors very fast flash77 18 7,682 Mar-05-2024, 06:12 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020