擅长:python、mysql、java
<p>假设您的代码如下所示:</p>
<pre><code>from tkinter import *
from tkinter.ttk import *
root = Tk()
def eastereggtxt1():
print("Easter Eggs!")
image = PhotoImage(file = r'easter_eggs.png') # I use easter_eggs as an example
image_button = Button(root, image = image, command = eastereggtxt1)
image_button.grid(row = 18, column = 7)
mainloop() # I just know that you can just do mainloop(), but it's not effective
</code></pre>
<p>我尝试了代码,它工作正常,但是当我尝试用其他东西替换<code>r</code>(例如:l,p,s)时,出现了一个错误:</p>
<pre><code>PS C:\Users\user#1> python -u "D:\Test\test1.py"
File "D:\Test\test1.py", line 9
img = PhotoImage(file = s'easter_eggs')
^
SyntaxError: invalid syntax
</code></pre>
<p>它表示代码不能使用除<code>r</code>以外的任何其他字符</p>
<p>你还提到:</p>
<blockquote>
<p>The image/button only shows up if I run it with the above character "r" included.</p>
</blockquote>
<p>我认为你的操作系统不支持没有字符<code>r</code>?如果这是错误的,请在评论中告诉我</p>
<p>和平:D</p>