首页 > 解决方案 > Tkinter Canvas - 在 y2 维度通过屏幕以防止滞后后删除形状时我遇到了一些问题

问题描述

我正在创建一个下雨效果功能,每当我尝试删除一个 y2 维度通过屏幕 y 轴的形状时,我都会遇到滞后问题。我无法完成这项工作。我的代码如下所示。

from tkinter import  *
import random
import time
window = Tk()
window.title('Raining Effects')
HEIGHT = 600
WIDTH = 1000
c = Canvas(window, height=HEIGHT, width=WIDTH, bg='yellow')
c.pack()
x2 = 
for q in range(6):
    c.create_oval(0, 0, 30, 30, outline='white', 
dif = 0
var = c.create_text(500, 580, text='Rain Count:', fill='blue', font='Consolas 20 bold')
def rain_part(event):
    global dif
    global lists
    dif += 1
    lists = []
    for i in range(1, 50, 1):
        x1 = random.randint(WIDTH / 100, WIDTH - 10)
        global y1
        y1 = random.randint(1, 20)
        global a
        a = c.create_line(x1, y1, x1 + 10, y1 + 10, fill='lightblue', width=3)
        lists.append(a)
        c.itemconfig(var, text='Rain Count:' + str(lists[-1] + dif - 1))

def del_part():
    # I have a problem creating the 'y2 dimension of shape passing y axis' condition
    c.delete(a)
def move_part(event):
    c.move('all', 0, 20)
    c.move(var, 0, -20)        
 


c.bind_all('<KeyPress-space>', rain_part)
c.bind_all('<Down>', move_part)

标签: pythontkintercanvastktkinter-layout

解决方案


推荐阅读