如何将两张不同的照片显示为海龟?
How to show two different photos as turtles?
我正在尝试导入两张不同的图片并使用 Turtle 将它们排成一行显示(当我设法这样做时它们应该会移动)但我找不到将它们一起显示的方法,我分配给乌龟的最后一张图片和屏幕正在接管。
这是我的代码:
from turtle import Turtle, Screen
from PIL import Image
screen = Screen()
height = 200
def create_players(height):
player = Turtle()
pic_name = input('write exact photo name: ')
image = Image.open(pic_name)
new_image = image.resize(((30, 30)))
pic_resized = 'pic_resized.gif'
new_image.save(pic_resized)
screen.addshape(pic_resized)
player.shape(pic_resized)
player.penup()
player.goto(-250, height)
return player
player1 = create_players(200)
player2 = create_players(150)
谢谢!
问题是这段代码:
pic_resized = 'pic_resized.gif'
new_image.save(pic_resized)
screen.addshape(pic_resized)
您已将两个 海龟图像指向相同 文件。我们只需要确保调整大小后的图像文件名是 unique:
from turtle import Screen, Turtle
from PIL import Image
def create_players(height):
pic_name = input("Write exact photo name: ")
image = Image.open(pic_name)
new_image = image.resize(((30, 30)))
pic_resized = pic_name + '_resized.gif'
new_image.save(pic_resized)
screen.addshape(pic_resized)
player = Turtle()
player.shape(pic_resized)
player.penup()
player.goto(-250, height)
return player
screen = Screen()
player1 = create_players(200)
player2 = create_players(150)
screen.exitonclick()
我正在尝试导入两张不同的图片并使用 Turtle 将它们排成一行显示(当我设法这样做时它们应该会移动)但我找不到将它们一起显示的方法,我分配给乌龟的最后一张图片和屏幕正在接管。 这是我的代码:
from turtle import Turtle, Screen
from PIL import Image
screen = Screen()
height = 200
def create_players(height):
player = Turtle()
pic_name = input('write exact photo name: ')
image = Image.open(pic_name)
new_image = image.resize(((30, 30)))
pic_resized = 'pic_resized.gif'
new_image.save(pic_resized)
screen.addshape(pic_resized)
player.shape(pic_resized)
player.penup()
player.goto(-250, height)
return player
player1 = create_players(200)
player2 = create_players(150)
谢谢!
问题是这段代码:
pic_resized = 'pic_resized.gif'
new_image.save(pic_resized)
screen.addshape(pic_resized)
您已将两个 海龟图像指向相同 文件。我们只需要确保调整大小后的图像文件名是 unique:
from turtle import Screen, Turtle
from PIL import Image
def create_players(height):
pic_name = input("Write exact photo name: ")
image = Image.open(pic_name)
new_image = image.resize(((30, 30)))
pic_resized = pic_name + '_resized.gif'
new_image.save(pic_resized)
screen.addshape(pic_resized)
player = Turtle()
player.shape(pic_resized)
player.penup()
player.goto(-250, height)
return player
screen = Screen()
player1 = create_players(200)
player2 = create_players(150)
screen.exitonclick()