以下のコードを書くとエラーで、
「 NameError: name 'Rect' is not defined 」 と
「 AttributeError: 'Tetris' object has no attribute 'statusbar' 」 が出ます。
前者は色々な記事をみてもスペルミスだとは思えません。
後者は調べたりしましたが意味がわかりません。
それぞれ原因を教えてください。
python2.7
wxpython4.0.0b1
pygame1.9.3
macOS10.12.6
# -*- coding: utf-8 -*- import wx import random import pygame class Menu(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, title = title, size = (425, 850)) self.game_state = GAME_MODE['START'] screen = pygame.display.set_mode(SCR_RECT.size) drow() def drow(self, screen): if self.game_state == GAME_MODE['START']: title_font = pygame.font.SysFont(None, 80) title = title_font.render('Puchi Puchi Shooting', False, (255, 0, 128)) screen.blit(title, ((SCR_RECT.width - title.get_width()) / 2, 200)) panel = wx.Panel(self) button = wx.Button(panel,label="exit",pos=(130,10),size=(60,60)) button2 = wx.Button(panel,label="exit2",pos=(130,70),size=(60,60)) self.Bind(wx.EVT_BUTTON, self.closebutton, button) if self.game_state == GAME_MODE['GAMEOVER']: # GAME OVERを描画 gameover_font = pygame.font.SysFont(None, 80) gameover = gameover_font.render("GAME OVER", False, (255, 0, 0)) screen.blit(gameover, ((SCR_RECT.width - gameover.get_width()) / 2, 200)) # 得点表示 score_font = pygame.font.SysFont(None, 80) score = score_font.render("You got {0:0>4d} points!".format(self.score), False, (255, 255, 255)) screen.blit(score, ((SCR_RECT.width - score.get_width()) / 2, 300)) def closebutton(self,event): self.Close(True) self.statusbar = self.CreateStatusBar() # ステータスバーの作成 self.statusbar.SetStatusText('0') # ステータスバーに 0 を表示 self.board = Board(self) # Boardクラスのインスタンスオブジェクト self.board.start() # Boardクラスのメソッドstart class Board(wx.Panel): : : 略 : if __name__ == '__main__': app = wx.App pygame.init() GAME_MODE = {'START': 0, 'GAMEOVER': 1} SCR_RECT = Rect(0, 0, 425, 850) # スクリーンサイズ(px指定) Menu(None, title = 'Tetris') app.MainLoop()
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。