使用Python的tkinter库创建游戏项目
使用tkinter
因为家教Alex的原因,接触到了tkinter,于是把过程记录在此
ONE
第一阶段,创建了两个正方形,游戏规则是,双人游戏控制正方形,只要碰撞到对方,游戏结束。
第一阶段代码
import time
import random
from tkinter import *
from tkinter import colorchooser
def hello():
print('hello there')
class P:
def __init__(self, x1, y1, x2, y2, canvas, color):
self.canvas = canvas
self.id = canvas.create_rectangle(x1, y1, x2, y2, fill=color)
# self.canva.move(self.id, 200, 300)
self.x = 0
self.y = 0
self.canvas_width = self.canvas.winfo_width()
self.canvas_height = self.canvas.winfo_height()
canvas.bind_all('<KeyPress-Up>', self.turn_up)
canvas.bind_all