Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Pyglet';s ScrollableTextLayout向上滚动,而不是向下滚动。视图y不';似乎没有文档中列出的效果_Python_Pyglet - Fatal编程技术网

Python 如何在Pyglet';s ScrollableTextLayout向上滚动,而不是向下滚动。视图y不';似乎没有文档中列出的效果

Python 如何在Pyglet';s ScrollableTextLayout向上滚动,而不是向下滚动。视图y不';似乎没有文档中列出的效果,python,pyglet,Python,Pyglet,我想知道如何让文本在Pyglet的ScrollableTextLayout中向上滚动,而不是向下滚动。为了清楚起见,这里有一个快速的快照来说明我所说的“向上”是什么意思。(以防万一) 我希望它表现如何: 根据文档,这种行为可以通过view_y属性实现,但我尝试了各种不同的值,但都没有明显的变化 守则: import pyglet class LoadDialog(pyglet.sprite.Sprite): def __init__(self): self.lbat

我想知道如何让文本在Pyglet的ScrollableTextLayout中向上滚动,而不是向下滚动。为了清楚起见,这里有一个快速的快照来说明我所说的“向上”是什么意思。(以防万一)

我希望它表现如何:

根据文档,这种行为可以通过view_y属性实现,但我尝试了各种不同的值,但都没有明显的变化

守则:

import pyglet

class LoadDialog(pyglet.sprite.Sprite):
    def __init__(self):
        self.lbatch = pyglet.graphics.Batch()

        self.loading_window = pyglet.image.load('..\\resources\\loading_base.png')
        super(LoadDialog, self).__init__(self.loading_window, batch=self.lbatch)


        self.doc = pyglet.text.decode_text('Hello world!'.ljust(40))
        self.doc.set_style(0,12, dict(font_name='Arial', font_size=12,
                                    color=(0,0,0,255)))

        self.layout = pyglet.text.layout.ScrollableTextLayout(self.doc, 
                                            width=self.load_animation.width, 
                                            height=100, multiline=True, batch=self.lbatch)
        self.layout.x = 220
        self.layout.y = 160
        self.layout.view_y = -80

    def update(self, dx):
        self.doc.insert_text(0, "New line".ljust(40))






sprite = LoadDialog()
window = pyglet.window.Window(width=640, height=480)

pyglet.gl.glClearColor(1, 1, 1, 1)

@window.event
def on_draw():
    window.clear()
    sprite.lbatch.draw()
    sprite.layout.draw()

@window.event
def update(dx):
    sprite.update(dx)

pyglet.clock.schedule_interval(update, 1.0)
pyglet.app.run()
我尝试了大量的
布局值。查看y
,从
-1
到荒谬的值,如
-3000
,或
500
,只是为了看看是否有变化。但它总是给出第一张图中所示的确切行为


我做错了什么?

首先,您的示例取决于图像文件及其宽度(未提供),这使测试稍微复杂一些

第二次,您正在通过调用创建,然后在此行的位置0(开始处)重复将文本插入到中:

def update(self, dx):
    self.doc.insert_text(0, "New line".ljust(40))
如果您希望文本显示在末尾,就像您在图形中暗示的那样,请将其插入末尾

def update(self, dx):
    # Fix the implied bug
    self.doc.insert_text(-1, "New line".ljust(40))
第三个,让我们回答您实际提出的问题。如果您阅读该属性的API文档,您会发现

超出范围[height-content_height,0]的值将自动在范围内剪裁

…因此,当“内容高度”为0时,将“视图y”设置为-80会导致“视图y”被剪裁为0,然后您再也不会尝试设置“视图y”。解决滚动问题的方法是在每次内容高度更改时设置视图y。对于一个简单的修复,您可以简单地设置view_y,以便内容的底部始终向上滚动到框架的底部:

def update(self, dx):
    # Fix the implied bug
    self.doc.insert_text(-1, "New line".ljust(40))
    # The answer to the stated question
    self.layout.view_y = -self.layout.content_height

这就是你问一个好问题的方式。