其他分享
首页 > 其他分享> > 我的诅咒盒子为什么不抽奖?

我的诅咒盒子为什么不抽奖?

作者:互联网

我在玩弄诅咒,无法在屏幕上画一个盒子.
我创建了一个有效的边框,但我想在边框中画一个框

这是我的代码

import curses 

screen = curses.initscr()

try:
    screen.border(0)
    box1 = curses.newwin(20, 20, 5, 5)
    box1.box()
    screen.getch()

finally:
    curses.endwin()

有什么建议吗?

解决方法:

curses docs开始:

When you call a method to display or erase text, the effect doesn’t
immediately show up on the display. …

Accordingly, curses requires that you explicitly tell it to redraw windows, using the refresh() method of window objects. …

您需要正确顺序的screen.refresh()和box1.refresh().

工作实例

#!/usr/bin/env python

import curses 

screen = curses.initscr()

try:
    screen.border(0)

    box1 = curses.newwin(20, 20, 5, 5)
    box1.box()    

    screen.refresh()
    box1.refresh()

    screen.getch()

finally:
    curses.endwin()

要么

#!/usr/bin/env python

import curses 

screen = curses.initscr()

try:
    screen.border(0)
    screen.refresh()

    box1 = curses.newwin(20, 20, 5, 5)
    box1.box()    
    box1.refresh()

    screen.getch()

finally:
    curses.endwin()

您可以使用immedok(True)自动刷新窗口

#!/usr/bin/env python

import curses 

screen = curses.initscr()
screen.immedok(True)

try:
    screen.border(0)

    box1 = curses.newwin(20, 20, 5, 5)
    box1.immedok(True)

    box1.box()    
    box1.addstr("Hello World of Curses!")

    screen.getch()

finally:
    curses.endwin()

标签:curses,python,draw
来源: https://codeday.me/bug/20191014/1912523.html