Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-24-2011, 11:18 AM   #1
Registered: Sep 2009
Distribution: raspbian
Posts: 94

Rep: Reputation: 15
python: writing to a curses window from a class

I'm trying to make a game in python with a nethack-style map, I'm using the curses module to organize my screen.
I have a class in a module ( called "Character", which will control npc movement. How can I make it so, when an npc moves or is created, the curses window mapwin in the main file ( updates?
Something like (in the Characters class)
def __init__(self,y,x):
  self.y=y#track character's
  self.x=x#y and x location
  #when created, place new character on 
  #map with the symbol "Q"
I can't figure out how to access the curses windows from an external class. Is it even possible?
Old 03-24-2011, 12:24 PM   #2
Senior Member
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
You'd have to pass it to the class. What you could do is add another variable:
class Characters:
    window = None
    def __init__(self,y,x,window=None):
        self.y = y
        self.x = x

        if window != None:
            Characters.window = window
You would then at some point need to initialise a character and pass the 'window' argument, so it sets the variable for all characters. Alternatively, you could remove it from the constructor, and make a new function called "setClassWindow(window)" or something similar, which just sets "Characters.window = window"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] python and curses : unable to getch() for a curses.KEY event mangec Programming 1 11-09-2010 05:21 PM
[SOLVED] Python n00b: promoting a derived class to base class? CoderMan Programming 2 03-11-2010 02:46 PM
Python Curses under Windows XP? introuble Programming 1 12-26-2006 08:59 AM
Messed up Python Curses happygiraffe98 Programming 2 12-02-2005 09:53 AM
python - make curses play nice w/ os.system() datadriven Programming 0 02-17-2005 04:31 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:09 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration