Last Item added to Scrollview is cut - kivy

As Long as all the Items inside the Scrollview are smaler than the screen itself everything is fine, as soon as they get bigger the Last Item at the bottom is beeing cut in half and i cant scroll to see it propperly.
Kivy:
GridLayout:
ScrollView:
size_hint_y: None
pos_hint: {'x':self, 'y':self}
do_scroll_x: False
do_scroll_y: True
size: root.width, root.height / 1.25
GridLayout:
cols:1
padding: 15
spacing:10
height: sum(x.height for x in self.children)
size_hint_y:None
id: Zitate
Python:
btn = Button(text = '\n"' + self.root.ids.Kommentar.text + '"' + "\n ~" + self.root.ids.field.text + "\n", size_hint = (0.8 , None))
self.root.ids.Zitate.add_widget(btn)

Replace:
height: sum(x.height for x in self.children)
with:
height: self.minimum_height
The function that you are trying to use is built in to the GridLayout.
You should also set a specific height for each Button.

Related

Adding width to parent layout by button release using Kivy language

I have a simple problem to which I cannot seem to find a straight answer. I am trying to, on a click of a child button, increase the parent layout width by a specific increment.
Here is an example of what I am trying to achieve:
GridLayout:
width: 200
size_hint_x: None
cols:1
Button:
size_hint:1, 0.07
text:"Add"
on_release: root.parent.width + 100
Button:
size_hint:1, 0.07
text:"Remove"
on_release: root.parent.width - 100
In this simple example by pressing the Add button should add 100 width to the parent grid layout and visa versa with the Remove button. However, not sure how to call the change of width with on_release: root.parent.width.
Any ideas?
When you refer to root.parent you are referring to whatever is containing the GridLayout that appears in your kv. If you want to adjust the size of the GridLayout, just use root.width. Also, using the + operator does not change the value, it just adds to value and returns the result. Try changing your kv to:
GridLayout:
width: 200
size_hint_x: None
cols:1
Button:
size_hint:1, 0.07
text:"Add"
on_release: root.width += 100
Button:
size_hint:1, 0.07
text:"Remove"
on_release: root.width -= 100

Can't update LABEL text on kivy file

I have a problem with updating a label text: id: time_ // the strange thing is , i can read(print) with self.ids.time_.text. Merci for help
class Scroll(Screen):
def __init__(self, **kwargs):
super(Scroll, self).__init__(**kwargs)
self.sec = 0
self.min = 0
def Label_updater(self,time):
print(self.ids.time_.text)
#self.ids.time_.text= str(time)
self.ids.time_.text='new_ text'
def start_timer(self, *args):
self.sec += 1
self.time = f'00:0{self.sec}'
self.Label_updater(self.time)
def on_start(self):
Clock.schedule_interval(self.start_timer, 1)
kivy file :
<Scroll>:
id: scroll_id
canvas:
Color:
rgba: 149 / 250.0, 77 / 250.0, 114 / 250.0, 0.9
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
spacing:7
padding:10
size_hint:(1,0.1)
pos_hint:{'top':1,'b':1}
Label:
id: score
text: 'Score: 00'
Label:
id: level
text: 'Level: 01'
Label:
id: time_
size_hint: (1.0, 0.83)
text: '00:00'
color: 'red'
BoxLayout:
size_hint:(1,0.9)
GamePage:
padding: 20,20,20,20
will try to explain the probleme with some pictures
in class GamePage i did create some Buttons with callback = pressed( )
in pressed from there u see the starter object activating start_timer() (( this will start the timer ))
enter image description here
enter image description here
when i push a Button ---> everything is working fine till i can print(self.ids.time_.text) and i see in logfile the timer working
but in the screen the Label text still 00:00
enter image description here
but if i press the button ( added from the kivy file ) everything is working fine
i want to start the timer when i push any button
enter image description here

Kivy TextInput how to change hint_text font size

Is there a way to change a TextInput hint_text font size in Kivy? I could not find any documentation on using something as hint_text_size.
TextInput:
id: text_input_unique
hint_text: 'example: Stand25'
hint_text_size: 16
multiline: False
size_hint_y: None
height: 50
font_size: 32
halign: 'center'
cursor_color: (0,0,0,1)
The TextInput uses the same font properties for hint_text as it does for the main text (except for color). Here is an extension of TextInput that honors a hint_font_size property:
class TextInputwHintSize(TextInput):
hint_font_size = NumericProperty(sp(15))
def __init__(self, **kwargs):
self.regular_font_size = sp(15)
self.ignore_font_size_change = False
super(TextInputwHintSize, self).__init__(**kwargs)
Clock.schedule_once(self.set_font_size)
def set_font_size(self, dt):
self.ignore_font_size_change = True
if self.text == '':
self.font_size = self.hint_font_size
def on_font_size(self, instance, size):
if self.ignore_font_size_change:
return
self.regular_font_size = size
def on_text(self, instance, text):
if text == '':
self.font_size = self.hint_font_size
else:
self.font_size = self.regular_font_size
for example, use this like:
TextInputwHintSize:
id: text_input_unique
hint_text: 'example: Stand25'
hint_font_size: 16
multiline: False
size_hint_y: None
height: 50
font_size: 32
halign: 'center'
cursor_color: (0,0,0,1)

How do I use widget collision to switch screens in kivy?

Im trying to create a game which consists of several areas, accessed by moving the circle onto the boundaries of the screen. I created a transit widget and defined a function to switch screens when there's a collision but it keeps giving errors. The error I got is that WindowManager does not have an attribute manager.
.py file:
class Transit(Widget):
def transit(self,circle):
if self.collide_widget(circle):
WindowManager.manager.current = "a1"
pass
class Wall(Widget):
def collision(self, circle):
if circle.collide_widget(self):
if circle.center_x > (self.pos[0] + self.size[0]) or circle.center_x < self.pos[0]:
circle.velocity_x = -1 * circle.velocity_x
elif circle.center_x > self.pos[0] and circle.center_x < (self.pos[0] + self.size[0]):
circle.velocity_y = -1 * circle.velocity_y
class Circle(Widget):
velocity_x = NumericProperty(0)
velocity_y = NumericProperty(0)
velocity = ReferenceListProperty(velocity_x, velocity_y)
def move(self):
self.pos = Vector(*self.velocity) + self.pos
class Move(Widget):
circle = ObjectProperty(None)
wall1 = ObjectProperty(None)
wall2 = ObjectProperty(None)
wall3 = ObjectProperty(None)
wall4 = ObjectProperty(None)
transit1 = ObjectProperty(None)
def __init__(self, **kwargs):
super(Move, self).__init__(**kwargs)
self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
self._keyboard.bind(on_key_down = self._on_keyboard_down)
Clock.schedule_interval(self.update, 0)
def update(self, dt):
self.circle.move()
self.wall1.collision(self.circle)
self.wall2.collision(self.circle)
self.wall3.collision(self.circle)
self.wall4.collision(self.circle)
self.transit1.transit(self.circle)
def _keyboard_closed(self):
self._keyboard.unbind(on_key_down=self._on_keyboard_down)
self._keyboard = None
def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
if keycode[1] == 'left':
self.circle.velocity_x -= 0.1
elif keycode[1] == 'right':
self.circle.velocity_x += 0.1
elif keycode[1] == 'up':
self.circle.velocity_y += 0.1
elif keycode[1] == 'down':
self.circle.velocity_y -= 0.1
return True
class Menu(Screen):
pass
class Start(Screen):
pass
class area1(Screen):
pass
class WindowManager(ScreenManager):
pass
kv = Builder.load_file("dw.kv")
class Adventure(App):
def build(self):
return kv
Adventure().run()
and heres my .kv file
Circle:
size: 30,30
canvas:
Ellipse:
pos: self.pos
size: self.size
WindowManager:
Menu:
Start:
area1:
Menu>:
name: "menu"
#Adding gridlayout
GridLayout:
rows :3
cols : 1
AnchorLayout:
anchor_x : "center"
anchor_y : "center"
Label:
text: "Adventure"
font_size: 40
AnchorLayout:
anchor_x : "center"
anchor_y : "center"
TextInput:
id: ign
size_hint : (.4, None)
height : 30
hint_text : "Enter your name"
multiline : False
AnchorLayout:
anchor_x : "center"
anchor_y : "center"
Button:
text: "Start"
font_size: 40
size: 100, 75
size_hint: (None, None)
on_release: app.root.current = "start"
Start>:
name: "start"
Move:
wall1 : r1
wall2 : r2
wall3 : r3
wall4 : r4
transit1 : t1
circle : circle
Circle:
id : circle
pos: root.center_x , root.center_y
Wall:
id : r1
pos: 0, 400
size: 350, 250
canvas:
Rectangle:
pos: self.pos
size: self.size
Wall:
id : r2
pos: 0 , 0
size: 350, 250
canvas:
Rectangle:
pos: self.pos
size: self.size
Wall:
id : r3
pos: 500 , 400
size: 800, 250
canvas:
Rectangle:
pos: self.pos
size: self.size
Wall:
id : r4
pos: 500 , 0
size: 800, 250
canvas:
Rectangle:
pos: self.pos
size: self.size
Transit:
id : t1
pos: 0, root.center_y
size: 1, 600
area1>:
name: 'a1'
Your only problem is that the line:
WindowManager.manager.current = "a1"
is trying to access the manager attribute of the WindowManager class. You actually want to access that attribute of the WindowManager instance. To do that, you can replace that line with:
App.get_running_app().root.current = "a1"

How to set fixed height of text input and stop overlapping of two text input in kivy?

Basically i want fixed text input height and don'n overlap two textinput
TextInput:
focus:True # cursor into textfield
cursor_color: .26,.26,.3,1 #cursor color
#size_hint: None, 1
#size: self.texture_size
foreground_color: .26,.26,.3,1 # Input text color
pos: root.width * .24,root.height * .47
width: root.width * .55
height:'34dp'
size_hint: (.2, None)
#size: (min(self.width,self.height),min(self.width,self.height))
#size_hint_min_y:self.minimum_height #used for fixed minimum height
#height:root*.9
#height:self.minimum_height
font_size:root.height * .03
hint_text:"please Enter your captha"
multiline:False
background_normal: "resource/images/rounded-image-green.jpg"
background_active: "resource/images/rounded-image-red.jpg"
padding_y: [self.height / 2.0 - (self.line_height / 2.0) * len(self._lines), 0]

Resources