【问题标题】:Scrolling the label滚动标签
【发布时间】:2015-03-29 17:42:39
【问题描述】:

我正在为自己编写一个小应用程序,但遇到了一些问题。 我无法使用 ScrollView 滚动标签。标签通过读取文本文件出现。

我展示了我的代码的一部分。

.py 代码:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView

class GeneralForm(TabbedPanel):
    txt_show = ObjectProperty()

    def SHOW_CONTENT(self):
        FILE=open('data')
        A=FILE.read()
        self.txt_show.text=A

class TimeTable(App):

    def build(self):
        return GeneralForm()

if __name__ == '__main__':
    TimeTable().run()

.kv 代码:

<GeneralForm>:
    do_default_tab: False
    txt_show:txt1
    TabbedPanelItem:
        text: 'Mon'
        on_release: root.SHOW_CONTENT()
        BoxLayout:
            orientation: 'vertical'
            ScrollView:
                size: self.size
                Label:
                    id:txt1
                    text: ''
                    size_hint_y: None
            BoxLayout:
                Button:
                    text: 'Edit'
                Button:
                    text: 'Exit'
    TabbedPanelItem:
        text: 'Tue'
    TabbedPanelItem:
        text: 'Wed'

“数据”文件是一个简单的 txt 文件,其中包含很多行文本。 当该文本显示在标签中时 - 它被截断。

如何为标签中的文本添加滚动?

提前致谢。

【问题讨论】:

    标签: python label scrollview kivy


    【解决方案1】:
    ScrollView:
        Label:
            id:txt1
            text: ''
            text_size: self.width, None  # Set the text wrap box width
            size_hint_y: None
            height: self.texture_size[1]  # Set the Label height to the text height
    

    【讨论】:

    • 非常感谢,帮到了。
    【解决方案2】:

    访问网站https://github.com/cbpowell/MarqueeLabel 并下载。 将 .m 和 .h 文件复制到您的项目并添加石英核心框架。 转到您的 .h 文件并导入 marquee.h 文件。

    #import <UIKit/UIKit.h>
    #import "MarqueeLabel.h"
    
    @interface PlayerViewController : UIViewController
    

    然后在 UIViewController 中创建一个标签,然后按住 ctrl 将其拖到 .h 文件中。保留插座选项,写下您想要的标签名称,将 UILabel 更改为 MarqueeLabel。 会是这样的:

    @property (strong, nonatomic) IBOutlet MarqueeLabel *nomeMusicaLabel;
    

    在视图中选择标签,转到屏幕右侧的实用工具栏,转到身份检查器(第三个按钮),将类更改为 MarqueeLabel。

    转到您的 .m 文件并编写以下代码:

    nomeMusicaLabel.text = @"Write your text here";
    self.nomeMusicaLabel.marqueeType = MLContinuous;
    self.nomeMusicaLabel.scrollDuration = 15.0;
    self.nomeMusicaLabel.animationCurve = UIViewAnimationOptionCurveEaseInOut;
    self.nomeMusicaLabel.fadeLength = 10.0f;
    self.nomeMusicaLabel.leadingBuffer = 30.0f;
    self.nomeMusicaLabel.trailingBuffer = 20.0f;
    

    在 MarkeeLabel zip 文件中,有许多其他类型的 scrool 文本的项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 2014-09-27
      • 2023-03-17
      相关资源
      最近更新 更多