builtins.name错误:未定义名称“self”

2024-09-30 18:22:44 发布

您现在位置:Python中文网/ 问答频道 /正文

在Windows7上使用Python3。在

import pickle
import os.path
from tkinter import * # Import tkinter
import tkinter.messagebox   

class Places:
  def __init__(self, name, street, city, state, zip):
    self.name = name
    self.street = street
    self.city = city
    self.state = state
    self.zip = zip

class PlacesBook:
  def __init__(self):      
    window = Tk() # Create a window
    window.title("PlacesBook") # Set title

我知道错误了builtins.name错误:在“类PlacesBook:”中未定义名称“self”:


Tags: nameimportselfstreetcitytitleinittkinter
1条回答
网友
1楼 · 发布于 2024-09-30 18:22:44

问题是你的缩进,在Python中缩进是非常重要的,那就是你如何定义类中的代码部分,方法。。。在

另一点,如果使用python3,那么所有类都必须从object继承。在

import pickle
import os.path
from tkinter import * # Import tkinter
import tkinter.messagebox

class Places(object):
    def __init__(self, name, street, city, state, zip):
        self.name = name
        self.street = street
        self.city = city
        self.state = state
        self.zip = zip

class PlacesBook(object):
    def __init__(self):
        window = Tk() # Create a window
        window.title("PlacesBook") # Set title

相关问题 更多 >