【问题标题】:How can I take input from something the Console has printed in Python?如何从控制台用 Python 打印的内容中获取输入?
【发布时间】:2020-06-27 19:03:49
【问题描述】:

我正在构建一个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" 的文本。

请帮助我,以便我完成这个项目。

【问题讨论】:

  • 代码在哪里?

标签: python debugging tkinter console


【解决方案1】:

您只需将其包含在您的代码中

try:
    #open file
except FileNotFoundError:
    print("No file found. Please check your directory or your spelling")

应该可以的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 2023-01-31
    • 2021-12-28
    • 2014-05-14
    • 2011-11-25
    • 1970-01-01
    相关资源
    最近更新 更多