[英]How can I take input from something the Console has printed in Python?
我正在构建一个Encrypter/Decrypter
,并且我已经让后端工作了。 要encrypt or decrypt a file
,您需要input the name and the extension
( Example: Image.png
)。
如果您输入的文件名不存在或有错字,控制台会打印:
FileNotFoundError: [Errno 2] No such file or directory:
继续您的输入文本。
我想要做的就像一个 If(控制台打印该错误消息),然后使用Tkinter
显示一个文本,上面写着"No file found. Please check your directory or your spelling"
。
请帮助我,这样我就可以完成这个项目。
您只需将其包含在您的代码中
try:
#open file
except FileNotFoundError:
print("No file found. Please check your directory or your spelling")
那应该可以
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.