所以我正在尝试编写一个程序,创建一个从左到右弹跳的红色立方体的短动画GIF。然而,当我将图像保存到GIF文件时,我陷入了困境,而且我已经到处搜索但我似乎无法弄清楚如何在不使用PIL或其他添加的情况下完成此操作。 (该程序适用于一个类,我们不能使用任何此类添加)
以下是我现在的代码。我一直在玩它很多,所以我之前使用过的一些代码已被注释掉了。
# BouncingCube.py
# This program is designed to produce an animated GIF displaying a red square bouncing back and forth between the left and right edges
import tkinter
from tkinter import *
import base64
root = Tk()
def fill_bg(image):
r,g,b = (255,255,255)
width = 110
height = 110
hexcode = "#%02x%02x%02x" % (r,g,b)
horizontal_line = "{" + " ".join([hexcode]*width) + "}"
image.put(" ".join([horizontal_line]*height))
def fill_box(image, color, pos):
r,g,b = color
width = 30
height = 30
x,y = pos
hexcode = "#%02x%02x%02x" % (r,g,b)
horizontal_line = "{" + " ".join([hexcode]*width) + "}"
image.put(" ".join([horizontal_line]*height), (y,x))
i = 0
while i != 90:
photo = PhotoImage(width=30, height=30)
fill_bg(photo)
fill_box(photo, (255,0,0), (40,i))
#label = tkinter.Label(root, image=photo)
#label.pack()
i = i + 10
while i != 0:
photo = PhotoImage(width=30, height=30)
fill_bg(photo)
fill_box(photo, (255,0,0), (40,i))
#label = tkinter.Label(root, image=photo)
#label.pack()
i = i - 10
#root.mainloop()
对于正确方向的任何帮助都会非常感激,即使它与我试图使用的方法完全不同。非常感谢!!