python - 为什么 python tkinter 模块即使有文件也找不到文件?
问题描述
所以我知道您可能已经阅读过类似的问题,但我的问题有点不同,我使用 python 3.8.3 并且我知道 python 基础知识,所以我想开始使用 GUI,我从 Tkinter 开始。我写了一个小程序,它什么都不做,我只是在尝试,但它不起作用,我不知道为什么。它给出了无法找到文件的错误,我尝试执行人们在其他问题中告诉的代码,但它不起作用,可能是由于 python 版本,这是我的代码:
from tkinter import *
window= Tk()
window.title("first GUI program of mine")
window.configure(background="black")
photo1 = PhotoImage(file="images.jpg")
Label (window, text="1 or 2 ? :", bg="black", fg="white", font="calibri 12 bold") .grid(row=1, column=0, sticky=W)
windows.mainloop()
所以当我运行它时,我得到这样的错误:
tkinter.TclError: couldn't open "images.jpg": no such file or directory
该文件位于保存 python 程序的同一文件夹中。
有任何想法吗?
解决方案
你能显示你的工作目录吗?我认为这是目录的问题。如果它在同一级别的目录下,也许你可以试试这个:'/images.jpg'
推荐阅读
- maven - maven 编译器插件如何进入有效的 POM,即使它不在 Super POM 中
- angular - NgRX provideMockStore createSelector 状态未定义
- python - 你应该如何用python更新本身就是值的键的JSON值
- r - 如何在R中列值大于20的情况下按降序对数据框(mtcars)的列进行排序
- python - Python Django Ajax获取请求在def函数中不起作用
- visual-studio - 为什么在 VS 2019 中出现智能错误
- angular - 如果我删除 node_modules 文件夹会发生什么?
- python - 多处理:将值并行分配给 N 维数组/矩阵
- asp.net-core-webapi - asp net core web api自定义模型验证
- python - 避免数据标签相互交叉 Matplotlib Python