Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7652019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:39:30+00:00 2026-05-31T11:39:30+00:00

I have the following Python (3.2) code: from pygame import * class Application: def

  • 0

I have the following Python (3.2) code:

from pygame import *

class Application:

    def __init__(self):
        self.running = True
        self.display_surface = None
        self.size = self.width, self.height = 640, 480

        self.old_ticks = pygame.time.get_ticks
        self.new_ticks = None

        pygame.init()
            self.display_surface = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)

    def on_event(self, event):
        if event.type == pygame.QUIT:
            self.running = False

    def on_loop(self):
        pass

    def on_render(self):
        pass

    def on_cleanup(self):
        pygame.quit()

    def regulate_time(self):
        self.new_ticks = pygame.time.get_ticks

        while (self.new_ticks < self.old_ticks + 1000):
            pass

        self.old_ticks = self.new_ticks

    def load_images(self):
        pass

    while(self.running == True):
        for event in pygame.event.get():
            self.on_event(event)

        self.regulate_time
        self.on_loop()
        self.on_render()

    self.on_cleanup()

    test = Application

I’m having a problem with the following line:

while(self.running == True):

which throws me the error : NameError: Name "self" is not defined.

I am pretty much a python newbie and was hoping to use this time to get started on learning python and pygame which I could then use for my college project (two birds with one stone) and I cannot figure out why this error is being thrown at me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:39:31+00:00Added an answer on May 31, 2026 at 11:39 am

    Well, the while(self.running == True) is not in any method (def) so there is no such variable called self in scope (which is what the NameError says)…

    …perhaps there is some missing indentation? Although the previous pass makes it look like more than this is missing: maybe def run(self):?

    Remember, self is just the conventional (and proper) name given to the first parameter for a method by which the “current instance” is implicitly passed.

    Happy coding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following chunk of python code: import hashlib class User: def _set_password(self,
I have the following situation in my python code: class Parent(object): def run(self): print
I have following python code: def scrapeSite(urlToCheck): html = urllib2.urlopen(urlToCheck).read() from BeautifulSoup import BeautifulSoup
i have the following code in a module called code_database.py class Entry(): def enter_data(self):
I have the following python code: import pty import subprocess os=subprocess.os from subprocess import
I have the following python code: from django.db import models from datetime import datetime
For the following Python code: first.py # first.py from second import Second class First:
I have the following Python code: import xml.dom.minidom import xml.parsers.expat try: domTree = ml.dom.minidom.parse(myXMLFileName)
In python I have the following function: def is_a_nice_element(element, parameter): #do something return True
I have the following python code... import Tkinter root = Tkinter.Tk() root.tk.eval('puts {printed by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.