Hello, I tried creating a text button that will hold any length of text. The width and height will adapt to the length of the text it holds.
`
`
I've tried everything but still, it's not working. Instead, I keep getting this error [CRITICAL] [Clock ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute. Remaining events:
I hope to get help here. Thank you.
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/cc3ad53b-8fa3-4c70-b291-fc734c3dbed0n%40googlegroups.com.
MDTextButton adapts to the size of the text as the default behavior. Here is a small example:
from kivymd.app import MDApp
from kivy.lang import Builder
kv = """
MDBoxLayout:
orientation: 'vertical'
AnchorLayout:
MDTextButton:
text: 'Short Text'
on_release: print(f'short button: {self.size}')
AnchorLayout:
MDTextButton:
text: 'Much longer text, does the button changes size?'
on_release: print(f'long button: {self.size}')
"""
class TextButtonApp(MDApp):
def build(self):
return Builder.load_string(kv)
TextButtonApp().run()
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/019101d9aa9a%244a0afd60%24de20f820%24%40cox.net.
Here is an example that dynamically sizes the button. A Label is used to calculate the texture size, and then set the size of the button.
from kivy.lang import Builder
from kivy.uix.label import Label
from kivymd.app import MDApp
from kivymd.uix.button import MDTextButton
kv = """
MDBoxLayout:
orientation: 'vertical'
AnchorLayout:
MDTextField:
id: input
hint_text: 'Enter Button Text'
on_text: sb.set_width(self.text)
AnchorLayout:
StretchButton:
id:sb
text: input.text
on_release: print(f'button size: {self.size}')
"""
class StretchButton(MDTextButton):
def set_width(self, text):
# create a label
label = Label(text=text, font_size=16)
# update the texture_size
label.texture_update()
# text size is now valid
self.width = label.texture_size[0]
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAF73fwsi_dQsbQ%2Bo6LkXH38U0kaT81TUs9-F3TOVXd5tVFNxgA%40mail.gmail.com.