当前位置:   article > 正文

求帮忙!!!在课堂上看的Python程序,运行出来全是一个黑的界面?应该是一个2048的界面啊_python跑完为什么会有黑图

python跑完为什么会有黑图
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import pyglet

# 设置棋盘大小
width = 530
heigh = 720

# 棋盘起始位置左下角的x、y
start_x = 15
start_y = 110

# 每行的块数
num = 4

#总宽度和每块的宽度
all_width = width - 2*start_x
dan_width = all_width/num

# 数字和背景设置不同颜色
label_color = (119,110,101,255)
bc_color = (250,248,239,255)

class Window(pyglet.window.Window): # 构造可视化界面,首先要实例化出一个窗体对象
    def __int__(self,*args,**kwargs):
        super().__init__(*args,**kwargs) #在类的继承中,如果你想要重写父类的方法而不是覆盖的父类方法,这个时候我们可以使用super()方法来实现
        self.game_init()
    def game_init(self):
        self.main_batch = pyglet.graphics.Batch()
        self.data = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]

        #背景
        back_img = pyglet.image.SolidColorImagePattern(color=bc_color)
        self.back = pyglet.sprite.Sprite(
            back_img.create_image(width,heigh),
            0,0)
        #title
        self.title_label = pyglet.text.Label(text='2048',
                                             bold = True,
                                             color = label_color,
                                             x = start_x,
                                             y= all_width+start_y-30,
                                             font_size=36,
                                             batch=self.main_batch)
        # score
        self.score = 0
        self.score_label = pyglet.text.Label(text='score = %d'%(self.score),
                                             bold = True,
                                             color = label_color,
                                             x = 200,
                                             y= all_width+start_y-30,
                                             font_size=36,
                                             batch=self.main_batch)
        # help
        self.help_label = pyglet.text.Label(text='please use up,down,->,<-,to play!',
                                             bold = True,
                                             color = label_color,
                                             x = start_x,
                                             y= start_y-30,
                                             font_size=18,
                                             batch=self.main_batch)


        def on_draw(self):
            self.clear()
            self.score_label.text = 'score = %d'%(self.score)
            self.back.draw()
            self.main_batch.draw()

win = Window(width,heigh)
icon = pyglet.image.load('icon.ico')
win.set_icon(icon)
pyglet.app.run()


                
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/219127
推荐阅读
相关标签
  

闽ICP备14008679号