【问题标题】:tkinter cannot locate image in PyCharm [duplicate]tkinter 无法在 PyCharm 中找到图像 [重复]
【发布时间】:2021-11-22 17:06:01
【问题描述】:

下面的代码是我尝试过的。我尝试使用其他代码,但结果都一样,图像没有显示。

from tkinter import *

root = Tk()
root.title('Using Icons, Images, and Exit Buttons')
root.iconbitmap('c:\Python images\die1.ico')

root.mainloop()

【问题讨论】:

    标签: python image tkinter pycharm


    【解决方案1】:

    由于 Micro$oft windoZe 坚持使用 \ 作为路径,您需要 r"c:\Python images\die1.ico" 来转义反斜杠,或者两个 \。否则表示“:”,这是一个非常不同的字符。

    但更好的是使用 pathlib.Path 或旧的 os.path 库为您处理所有这些。

    【讨论】:

      猜你喜欢
      • 2011-03-22
      • 2020-01-10
      • 2016-09-09
      • 2017-12-24
      • 2020-12-24
      • 1970-01-01
      • 2020-02-19
      • 1970-01-01
      • 2013-04-30
      相关资源
      最近更新 更多