栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python tkinter 中 update()为何报TCLError?

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python tkinter 中 update()为何报TCLError?

w.update()
为何报TCLError?

import tkinter as tk
import sys
from random import randint
import time
w=tk.Tk()
w.geometry('800x500')
canvas=tk.Canvas(w, width=800, height=500, bg="white")
SIZE=40
def close():
    sys.exit()
class S:
    def __init__(self,x,y):
        self.x=x
        self.y=y
        self.lose=False
        self.rect=canvas.create_rectangle(x,y,x+SIZE,y+SIZE,fill="blue")
        self.speed=1
    def move(self):
        self.y+=self.speed
        if self.y<0:
            self.speed=1
        elif self.y>500:
            self.lose=True
        self.speed+=0.1
        canvas.coords(self.rect,self.x,self.y,self.x+SIZE,self.y+SIZE)
class B:
    def __init__(self):
        self.l=randint(150,250)
        self.x=800
        self.des=False
        self.rect1=canvas.create_rectangle(800,0,850,self.l,fill="yellow")
        self.rect2=canvas.create_rectangle(800,self.l+150,850,500,fill="yellow")
    def move(self):
        self.x-=5
        if self.x<-50:
            self.des=True
            return
        canvas.coords(self.rect1,self.x,0,self.x+50,self.l)
        canvas.coords(self.rect2,self.x,self.l+150,self.x+50,500)
    def hit(self):
        if s.x+SIZE>self.x and s.xself.l+150):
            s.lose=True
canvas.focus_set()
s=S(0,0)
bs=[]
canvas.pack()
RESET=False
def up(e):
    s.speed=-4
def rm():
    i=0
    while i", up)
w.bind("",reset)
w.bind("",close)
s.move()
w.update()
time.sleep(1)
last=0
while True:
    while True:
        s.move()
        if time.time()-last>1:
            bs.append(B())
            last=time.time()
        for b in bs:
            b.move()
            b.hit()
        rm()
        w.update()
        if s.lose:
            canvas.create_text(400,225,text="You lose!",font=('Arial',50))
            break
        time.sleep(0.005)
    while True:
        if RESET:
            #w.update()
            break
        
       
        w.update()
    RESET=False

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/769647.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号