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

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

这是我的代码

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()
上一篇:python-如何禁用控制字符的外壳程序拦截?


下一篇:c – OSX Lion上的curses.h问题