gui 零找不到图像
我正在开发一个程序,该程序将随机选择并显示 5 张塔罗牌。遗憾的是我不断收到此错误(*** GUIZERO 错误 *** 图像导入错误 - '[Errno 2] 没有这样的文件或目录:'6.png'' 检查文件路径和图像类型是 GIF/Animated GIF/BMP/ICO/PNG/JPG/TIF)。所有图像都与我正在运行的脚本文件位于完全相同的目录中,所以我不知道该怎么做。使用完整路径不是一个选项,因为我希望该项目能够在不同的位置工作。如果你们能给我一些指点,那就太好了!
我的代码:
`from random import*
from guizero import App, Picture, PushButton
#### lists and other variables ####
cards = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
drawn_cards = []
card1 = ()
card2 = ()
card3 = ()
card4 = ()
card5 = ()
#### functions ####
def display_cards():
pic1 = Picture(app, image =(card1+".png"),align="top")
pic2 = Picture(app, image =(card2+".png"),align="left")
pic3 = Picture(app, image =(card3+".png"),align="left")
pic4 = Picture(app, image =(card4+".png"),align="left")
pic5 = Picture(app, image =(card5+".png"),align="bottom")
def card_drawer():
global cards
global drawn_cards
global card1
global card2
global card3
global card4
global card5
loops = 0
while loops < 5:
drawn = (choice(cards))
drawn_cards.append(drawn)
cards.remove (drawn)
loops = loops + 1
card1 = (drawn_cards[0])
card2 = (drawn_cards[1])
card3 = (drawn_cards[2])
card4 = (drawn_cards[3])
card5 = (drawn_cards[4])
card1 = str(card1)
card2 = str(card2)
card3 = str(card3)
card4 = str(card4)
card5 = str(card5)
display_cards()
#### gui stuff ####
app = App()
reading = PushButton(app, text = "draw cards",align="bottom", command = card_drawer)`
im working on a program that will randomly choose and display 5 tarot cards. sadly i keep getting this error (*** GUIZERO ERROR ***
Image import error - '[Errno 2] No such file or directory: '6.png''
Check the file path and image type is GIF/Animated GIF/BMP/ICO/PNG/JPG/TIF). all of the images are in the exact same directory as the script file im running so i have no clue what to do. using the full path is not an option as i want this project to beable to work in a differnt location. if you guys could give me some pointers that would be great!
my code:
`from random import*
from guizero import App, Picture, PushButton
#### lists and other variables ####
cards = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
drawn_cards = []
card1 = ()
card2 = ()
card3 = ()
card4 = ()
card5 = ()
#### functions ####
def display_cards():
pic1 = Picture(app, image =(card1+".png"),align="top")
pic2 = Picture(app, image =(card2+".png"),align="left")
pic3 = Picture(app, image =(card3+".png"),align="left")
pic4 = Picture(app, image =(card4+".png"),align="left")
pic5 = Picture(app, image =(card5+".png"),align="bottom")
def card_drawer():
global cards
global drawn_cards
global card1
global card2
global card3
global card4
global card5
loops = 0
while loops < 5:
drawn = (choice(cards))
drawn_cards.append(drawn)
cards.remove (drawn)
loops = loops + 1
card1 = (drawn_cards[0])
card2 = (drawn_cards[1])
card3 = (drawn_cards[2])
card4 = (drawn_cards[3])
card5 = (drawn_cards[4])
card1 = str(card1)
card2 = str(card2)
card3 = str(card3)
card4 = str(card4)
card5 = str(card5)
display_cards()
#### gui stuff ####
app = App()
reading = PushButton(app, text = "draw cards",align="bottom", command = card_drawer)`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,Windows 认为名称如 1.png 的文件被命名为整数而不是字符串,我将文件的编号切换为罗马数字,它起作用了。
as it turns out, windows thinks that files with names such as 1.png are named as intergers and not strings, i switched numbering of the files to roman numerals and it worked.