小编of.*_*z10的帖子

Tkinter 标签图像设置不起作用

我一直在学习如何从头开始使用 Tkinter,同时尝试在框架中设置一个简单的 Label 小部件:

from Tkinter import *
from ttk import *

root = Tk()
root.title("Practice")

mainW = LabelFrame(root, text = "Main info")
mainW.grid()

image = Label(mainW, image = "C:\Users\Oscar Ramirez\Pictures\image.png")
image.grid(column = 0, row = 0)

codeEntry = Entry(mainW, text = "User Code")
codeEntry.grid(column = 1, row = 0)

root.mainloop()
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Traceback (most recent call last):
  File "Tutorial.py", line 10, in <module>
    image = Label(mainW, image = "C:\Users\Oscar Ramirez\Pictures\image.png")
  File "C:\Python27\lib\lib-tk\ttk.py", line 757, in __init__
Widget.__init__(self, master, "ttk::label", kw) …
Run Code Online (Sandbox Code Playgroud)

python label tkinter python-2.7

2
推荐指数
1
解决办法
3318
查看次数

标签 统计

label ×1

python ×1

python-2.7 ×1

tkinter ×1