python - 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)
解决方案
推荐阅读
- java - proguard 在使用转换方法引用时是否有问题?
- maven - Maven 项目初始化程序
- testing - 我是 Protractor 测试的新手,请您告诉我如何为登录网页编写脚本并转到下一页
- google-chrome - 在 Windows 和 Android 上使用 Chrome 选择证书
- python - 如何根据其他非相关模型过滤django模型
- java - Spring - 使用 x-www-form-urlencoded 错误编码 POST 请求
- c# - EF 两个干扰上下文
- ionic-framework - Ionic 4 build for release 不工作,调试 apk 工作
- json - 如何在sql查询中调用Json
- c - printf() 重定向到命令行中的文件 (Cygwin)