简体   繁体   English

python curses tty screen blink

[英]python curses tty screen blink

I'm writing a python curses game ( https://github.com/pankshok/xoinvader ). 我正在写一个python curses游戏( https://github.com/pankshok/xoinvader )。 I found a problem: in terminal emulator it works fine, but in tty screen blinks. 我发现了一个问题:在终端模拟器中它工作正常,但在tty屏幕闪烁。 I tried to use curses.flash(), but it got even worse. 我试图使用curses.flash(),但它变得更糟。

for example, screen field: 例如,屏幕字段:

self.screen = curses.newwin(80, 24, 0, 0)

Main loop: 主循环:

def loop(self):
    while True:
        self.events()
        self.update()
        self.render()

render: ( https://github.com/pankshok/xoinvader/blob/master/xoi.py#L175 ) 渲染:( https://github.com/pankshok/xoinvader/blob/master/xoi.py#L175

self.screen.clear()
#draw some characters    
self.screen.refresh()
time.sleep(0.03)

Constant time in sleep function is temporary, until I write 60 render calls controller. 睡眠功能的恒定时间是暂时的,直到我写入60个渲染调用控制器。

How to implement render method correctly? 如何正确实现渲染方法?

Thanks in advance, Paul. 保罗先生,谢谢。

Don't call clear to clear the screen, use erase instead. 不要打电话clear以清除屏幕,而是使用erase Using clear sets a flag so that when you call refresh the first thing it does is clear the screen of the terminal. 使用clear设置一个标志,这样当你调用refresh ,它所做的第一件事就是清除终端的屏幕。 This is what is causing the terminal's screen to appear to blink. 这是导致终端屏幕显示闪烁的原因。 The user sees the old screen, then a completely blank screen, then your new screen. 用户看到旧屏幕,然后是完全空白的屏幕,然后是新屏幕。 If you use erase then it will instead modify the old screen to look like the new one. 如果你使用erase那么它将修改旧屏幕看起来像新屏幕。

You may still see some odd flashing or other artifacts on slow terminals. 您可能仍会在慢速终端上看到一些奇怪的闪烁或其他伪影。 Try calling screen.idcok(False) and screen.idlok(False) to stop curses from using insert and deletion operations to update the screen. 尝试调用screen.idcok(False)screen.idlok(False)来阻止curses使用插入和删除操作来更新屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM