Reputation: 41
I'm trying to setup a day and month display.
In the planner.kv file I can't get the Telldate
child widget to work with pos_hint
in FloatLayout
but it seems to be working fine with Button
.
I'm not sure if i've set up FloatLayout
properly or if I'm going about it in the wrong way.
I understand that Telldate
is a custom widget and a child widget when inside FloatLayout
unless I'm wrong about that.
Everything else is working as intended
main.py
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from time import strftime
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
class Telldate(Widget):
todayday = ObjectProperty('')
def __init__(self,*args, **kwargs):
super().__init__(*args, **kwargs)
self.todayday= strftime('%A')
class PlannerApp(App):
pass
if __name__ == '__main__':
PlannerApp().run()
planner.kv
<Telldate>:
Button:
size:(50,50)
text:self.parent.todayday
FloatLayout:
Button:
text: 'ay'
size_hint:(None,None)
pos_hint: { 'x': 0.5, 'y': 0.8}
Telldate:
size_hint:(None,None)
pos_hint: { 'x': 0.5, 'y': 0.8}
I'm using python V3.6.2 and Kivy v1.10.0 with IDLE V3.6.2 Thanks for your patience!
----Edit1:---
using
class Telldate(FloatLayout):
instead of
class Telldate(Widget):
allows me to set hint_size because i'm now inheriting FloatLayout properties and not widget properties but still doesn't allow hint_pos to be set. The rest of the code is still the same.
Upvotes: 2
Views: 1794
Reputation: 41
So what I learnt was that widgets don't inherit properties of layouts which is where my troubles began with Telldate(Widget)
, i found this in the documentations for widget.
Using Telldate(FloatLayout)
instead and calling(not sure if the right terminology) the class Telldate
via <Telldate>
into kivy solved my issue.
And then creating FloatLayout for whenever I want to call a custom widget as in the .kv file
planner.kv
<Tellday@Label>:
size:(50,50)
<Telldate>:
FloatLayout:
Tellday:
size_hint:( None,None)
text: self.parent.parent.todayday
pos_hint:{'top': 0.5,'right':0.5}
main.py
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from time import strftime
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.lang import Builder
class Telldate(FloatLayout):
todayday= ObjectProperty('')
# todaymonth = ObjectProperty('')
def __init__(self,*args, **kwargs):
super().__init__(*args, **kwargs)
self.todayday=strftime('%A')
self.todayday= strftime('%A')
# self.todaymonth= strftime('%b')
class PlannerApp(App):
def build(self):
return Telldate()
if __name__ == '__main__':
PlannerApp().run()
hope this helps someone!
Upvotes: 1