求帮忙!!!在课堂上看的Python程序,运行出来全是一个黑的界面?应该是一个2048的界面啊

#!/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()


                
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值