本文介绍了适用于 Windows 的 Curses 替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 windows 中,python 是否有其他可用的 curses 模块替代?我在 python 文档中查找,但其中提到它用于在 unix 中使用.我对这些不太熟悉,那么有没有办法在windows中使用curses模块,或者是否有一些专门用于windows的类似模块?[我使用的是 Python 3.3]

Is there any alternative of the curses module for python to use in windows? I looked up in the python documentation, but there its mentioned that its for using in unix. I am not much familiar with these, so is there some way to use curses module in windows or is there some similar module specially for windows?[I am using Python 3.3]

推荐答案

那恐怕你就不走运了.没有真正的跨平台版本或 curses/ncurses 的端口,有一个对话"端口可以工作,但功能有限.

Then you're out of luck i'm afraid.There's no real cross-platform version or port of curses/ncurses, there is a "dialogue" port which works, but it's limited in capabilities.

您最好的选择是运行 CygWin 或 MinGW32,在宽松的术语"中,两者都是 Linux 系统+终端模拟器,其中包含您需要的大部分二进制文件.他们可以在终端内运行本地 Linux/Unix 二进制文件并随时访问您的主机"系统文件,所以这就像使用来自 Linux 世界的所有好东西用踢屁股终端修补 Windows.您仍然需要一些 Linux 的基本知识以及命令等的工作原理,但您会明白的.

Your best bet is to run CygWin or MinGW32, both are, in "loose terms", a Linux system+terminal emulator which has much of the binaries you need. They can run native Linux/Unix binaries inside the terminal and access your "host" system files at any time, so it's like patching Windows with a kick-ass terminal with all your goodies from the Linux world.You'll still need some basic knowledge of Linux and how the commands etc work, but you'll figure it out.

import pyglet
from pyglet.gl import *

class main (pyglet.window.Window):
    def __init__ (self):
        super(main, self).__init__(800, 600, fullscreen = False)
        self.button_texture = pyglet.image.load('button.png')
        self.button = pyglet.sprite.Sprite(self.button_texture)

        ## --- If you'd like to play sounds:
        #self.sound = pyglet.media.load('music.mp3')
        #self.sound.play()

        self.alive = 1

    def on_draw(self):
        self.render()

    def on_close(self):
        self.alive = 0

    def on_mouse_press(self, x, y, button, modifiers):
        if x > self.button.x and x < (self.button.x + self.button_texture.width):
            if y > self.button.y and y < (self.button.y + self.button_texture.height):
                self.alive = 0

    def on_key_press(self, symbol, modifiers):
        if symbol == 65307: # [ESC]
            self.alive = 0

    def render(self):
        self.clear()
        self.button.draw()
        self.flip()

    def run(self):
        while self.alive == 1:
            self.render()

            # -----------> This is key <----------
            # This is what replaces pyglet.app.run()
            # but is required for the GUI to not freeze
            #
            event = self.dispatch_events()


x = main()
x.run()

这是该代码的输出:

这篇关于适用于 Windows 的 Curses 替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:45