I am trying to get a image to position itself at the bottom right hand corner of the screen with pos_hint but it always leaves a gap between the bottom of the image and the screen, im still very new to kivy and have looked around for a solution but cant find anything that helps, thanks in advance
class Building(Image):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.source = 'Building.png'
self.size_hint = 0.4,1
self.pos_hint = {'x':0.7, 'y':0.1}
This is where i call it
self.build = Building()
self.add_widget(self.build)
There are two issues that may be causing the gap. One is that your code:
self.pos_hint = {'x':0.7, 'y':0.1}
is setting a gap of one tenth of the container height.
The second issue is that Image
, by default, will not stretch the underlying image, and will not distort the image (stretching more in one direction than the other). So, you can get what you want by modifying your Building
class like this:
class Building(Image):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.source = 'Building.png'
self.size_hint = 0.4,1
self.pos_hint = {'right':1.0, 'y':0} # position image at right, bottom
self.allow_stretch = True # allow image to be stretched
self.keep_ratio = False # allow distortion
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.