Pygame和课程

问题描述 投票:2回答:1

所以我在课堂上制作一个tkinter / pygame游戏,而当python在课堂上时,python无法识别pygame。(不必担心我将如何分别启动窗口,一旦窗口工作就会完成]

from tkinter import *
from pygame import *
class firstscreen:
    def __init__(self):
        self.window = Tk()
        self.window.minsize(300, 250)
        self.window.resizable(width=False, height=False)
        self.window.title("Login")
        self.username = ""
        self.password = ""
        self.userlabel = Label(self.window, text="Username")
        self.userlabel.place(x=50, y=50)
        self.passlabel = Label(self.window, text="Password")
        self.passlabel.place(x=50, y=100)
        self.userentry = Entry(self.window, textvariable=self.username)
        self.userentry.place(x=110, y=50)
        self.passentry = Entry(self.window, textvariable=self.password, show="*")
        self.passentry.place(x=110, y=100)
        self.loginbutton = Button(self.window, text="Login", command = self.login())
        self.loginbutton.place(x=80, y=140)
        self.registerbutton = Button(self.window, text="Register",command=self.login())
        self.registerbutton.place(x=140, y=140)
        self.window.mainloop()
    def login(self):
        print("Hello")

class gamewindow():
    def __init__(self):
        pygame.init()
        game = pygame.display.set_mode((800, 300))
runlogin = firstscreen()
rungame = gamewindow()
NameError:name 'pygame' is not defined

(对于第29行,pygame.init()]

python pygame subclass
1个回答
0
投票

必须是]

from pygame import *

# [...]

init()

import pygame

# [...]

pygame.init()
© www.soinside.com 2019 - 2024. All rights reserved.