如何使用在同一脚本中创建的文件
How to use a file that was created in the same script
我正在尝试获取 OSMNx 地图作为图像,然后使用相同的图像作为 pygame 背景图像
这是我试过的:
import osmnx as ox
import pygame
from IPython.display import Image
ox.config(log_file=True,log_console=True,use_cache=True)
img_folder='image'; extension='png'; size=700
place='Prague'
point=(50.0908,14.4009)
fig,ax=ox.plot_figure_ground(point=point,filename=place,network_type='all',dpi=150)
Image('{}/{}.{}'.format(img_folder,place,extension),height=size,width=size)
SCREEN_WIDTH, SCREEN_HEIGHT = size, size
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption('Top Down Car Using OOP')
pygame.image.load(Image('{}/{}.{}'.format(img_folder,place,extension)))
脚本创建了三个文件夹:logs、cache、images,我想从文件夹images中获取图片,但是找不到路径
非常感谢
不好意思,我是自己想出来的,就在我发这个问题的时候,遇到了第二次...
如果以后有人遇到类似问题,这是我的解决方案:
import osmnx as ox
import pygame
from IPython.display import Image
ox.config(log_file=True,log_console=True,use_cache=True)
img_folder='image'; extension='png'; size=700
place='Prague'
point=(50.0908,14.4009)
fig,ax=ox.plot_figure_ground(point=point,filename=place,network_type='all',dpi=150)
Image('{}/{}.{}'.format(img_folder,place,extension),height=size,width=size)
SCREEN_WIDTH, SCREEN_HEIGHT = size, size
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption('Top Down Car Using OOP')
background_image = pygame.image.load("images\{}.{}".format(place,extension))
k = 0
Pixels = []
FPS = 24
running = True
screen.blit(background_image, [0, 0])
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
# The user closed the window or pressed escape
running = False
pygame.display.flip()
pygame.time.Clock().tick(FPS)
pygame.quit()
print('Done!')
抱歉打扰了,但如果可能的话,我想知道 Lior Cohen 在评论中的 slash\backslash 符号是什么意思,我不得不承认我很困惑。
我正在尝试获取 OSMNx 地图作为图像,然后使用相同的图像作为 pygame 背景图像
这是我试过的:
import osmnx as ox
import pygame
from IPython.display import Image
ox.config(log_file=True,log_console=True,use_cache=True)
img_folder='image'; extension='png'; size=700
place='Prague'
point=(50.0908,14.4009)
fig,ax=ox.plot_figure_ground(point=point,filename=place,network_type='all',dpi=150)
Image('{}/{}.{}'.format(img_folder,place,extension),height=size,width=size)
SCREEN_WIDTH, SCREEN_HEIGHT = size, size
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption('Top Down Car Using OOP')
pygame.image.load(Image('{}/{}.{}'.format(img_folder,place,extension)))
脚本创建了三个文件夹:logs、cache、images,我想从文件夹images中获取图片,但是找不到路径 非常感谢
不好意思,我是自己想出来的,就在我发这个问题的时候,遇到了第二次...
如果以后有人遇到类似问题,这是我的解决方案:
import osmnx as ox
import pygame
from IPython.display import Image
ox.config(log_file=True,log_console=True,use_cache=True)
img_folder='image'; extension='png'; size=700
place='Prague'
point=(50.0908,14.4009)
fig,ax=ox.plot_figure_ground(point=point,filename=place,network_type='all',dpi=150)
Image('{}/{}.{}'.format(img_folder,place,extension),height=size,width=size)
SCREEN_WIDTH, SCREEN_HEIGHT = size, size
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption('Top Down Car Using OOP')
background_image = pygame.image.load("images\{}.{}".format(place,extension))
k = 0
Pixels = []
FPS = 24
running = True
screen.blit(background_image, [0, 0])
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
# The user closed the window or pressed escape
running = False
pygame.display.flip()
pygame.time.Clock().tick(FPS)
pygame.quit()
print('Done!')
抱歉打扰了,但如果可能的话,我想知道 Lior Cohen 在评论中的 slash\backslash 符号是什么意思,我不得不承认我很困惑。