Reputation: 451
I have a popup in Kivy, and I would like for it to have an image that has a size_hint
of (0.5, 0.5)
, but when I try to set this, the image moves.
My current code:
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.popup import Popup
from kivy.uix.image import Image
import kivy
kivy.require('1.11.1')
class TestApp(App):
def build(self):
return Button(text='Open Popup', on_press=self.open)
def open(self, button):
Popup(title='Popup', size_hint=(0.5, 0.5), content=Image(source='testing.png', size_hint=(0.5, 0.5))).open()
TestApp().run()
The current code gives this outcome:
If anyone could help me, that would be great!
Upvotes: 0
Views: 284
Reputation: 631
You have to use the pos_hint parameter. This should fix it:
def open(self, button):
Popup(title='Popup',
size_hint=(0.5, 0.5),
content=Image(source='testing.png',
size_hint=(0.5, 0.5),
pos_hint={'center_x': 0.5, 'center_y': 0.5})).open()
More info at https://blog.kivy.org/2014/01/positionsize-of-widgets-in-kivy/
Upvotes: 1
Reputation:
you could use the Pixlr Editor to resize the image, and then use a turtle to move the image where you want:
import turtle
t = turtle.turtle
t.shape("testing.png")
#use the .forward() functions to move it
t.forward(10)
Upvotes: 0