如何在运行时动态调整标签或按钮的大小,特别是text_size和height,具体取决于文本的数量?
我知道这个问题已经以一种方式回答了这个问题:
我在部分代码中反映了这个例子.
问题是在运行时动态调整标签和按钮的大小.使用,例如:
btn = Button(text_size=(self.width, self.height), text='blah blah')
Run Code Online (Sandbox Code Playgroud)
...等等,只使程序认为(并且逻辑上如此)"self"指的是包含按钮的类.
那么,如何在python语言中动态调整这些属性的大小,而不是kivy呢?
我的示例代码:
import kivy
kivy.require('1.7.2') # replace with your current kivy version !
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
i = range(20)
long_text = 'sometimes the search result could be rather long \
sometimes the search result could be rather long \
sometimes the search result could be rather long '
class ButtonILike(Button): …Run Code Online (Sandbox Code Playgroud) 所以,我认为至少应该有两种方法可以在此页面上显示下拉菜单,但我无法使用这两种方法。我是 kivy 和编程的新手,但我已经阅读了文档,似乎我根本不明白。
我创建了以下示例:
import kivy
kivy.require('1.7.2') # replace with your current kivy version !
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty
from kivy.uix.button import Button
from kivy.uix.dropdown import DropDown
class CustomDropDown(DropDown):
pass
class HomeScreen(Screen):
translateInput = ObjectProperty(None)
translateButton = ObjectProperty(None)
translateLabel = ObjectProperty(None)
top_layout = ObjectProperty(None)
dd_btn = ObjectProperty(None)
drop_down = CustomDropDown()
#notes_dropdown = ObjectProperty(None)
dropdown = DropDown()
notes = ['Features', 'Suggestions', 'Abreviations', 'Miscellaneous']
for note in notes:
# when adding widgets, we …Run Code Online (Sandbox Code Playgroud)