ecoe
ecoe

Reputation: 5322

How to position Kivy Popup with absolute coordinate?

How do you disable relative position for a Kivy Popup object? For example, how would you define absolute pos for this example?:

from kivy.uix.popup import Popup
from kivy.uix.label import Label
popup = Popup(title='Test popup', content=Label(text='Hello world'),
              size_hint=(None, None), 
              #pos_hint=None, pos_hint=(None, None), pos_hint={}, 
              size=(200,200), pos=(10, 10))
popup.open()

Notice if the pos_hint attempts are uncommented, it fails either because pos_hint mustn't be null, cannot be a tuple, or simply has no effect (the popup is always centered vertically and horizontally). Notice also that the custom size does work.

Upvotes: 1

Views: 2813

Answers (2)

Yoav Glazner
Yoav Glazner

Reputation: 8066

Since pos_hint works well you can always do: ("10.0" is the absolute coordinate )

    popup = Popup(title='Test popup', content=Label(text='Hello world'),
                  size_hint=(None, None), 
                  pos_hint={'x': 10.0 / Window.width, 
                            'y':10.0 /  Window.height},  
                  size=(200,200), #pos=(10, 10),

                  )

The only problem here is that you'll have to update the pos_hint on a re-size event

Upvotes: 1

inclement
inclement

Reputation: 29458

pos_hint should be a dict, not a tuple, so probably pos_hint={} or pos_hint=None will work (but I'm not sure which).

Upvotes: 0

Related Questions