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]
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.
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()
Here's the output of that code:
(Pyglet is "cross-platform" and doesn't care about the Python version at all)