gpt4 book ai didi

Python-属性错误: 'str' object has no attribute 'items'

转载 作者:行者123 更新时间:2023-11-30 21:49:50 24 4
gpt4 key购买 nike

我是 Tkinter 的初学者。我正在尝试制作一个电话簿 GUI 应用程序。

所以,我才刚刚开始,这是我的源代码:

#This is my python 'source.py' for learning purpose

from tkinter import Tk
from tkinter import Button
from tkinter import LEFT
from tkinter import Label
from tkinter import Frame
from tkinter import Pack

wn = Tk()
f = Frame(wn)

b1 = Button(f, "One")
b2 = Button(f, "Two")
b3 = Button(f, "Three")

b1.pack(side=LEFT)
b2.pack(side=LEFT)
b3.pack(side=LEFT)

l = Label(wn, "This is my label!")

l.pack()
l.pack()

wn.mainloop()

当我运行时,我的程序出现以下错误:

/usr/bin/python3.4 /home/rajendra/PycharmProjects/pythonProject01/myPackage/source.py
Traceback (most recent call last):
File "/home/rajendra/PycharmProjects/pythonProject01/myPackage/source.py", line 13, in <module>
b1 = Button(f, "One")
File "/usr/lib/python3.4/tkinter/__init__.py", line 2164, in __init__
Widget.__init__(self, master, 'button', cnf, kw)
File "/usr/lib/python3.4/tkinter/__init__.py", line 2090, in __init__
classes = [(k, v) for k, v in cnf.items() if isinstance(k, type)]
AttributeError: 'str' object has no attribute 'items'

Process finished with exit code 1

谁能告诉我这里出了什么问题吗?

非常感谢您的帮助!

最佳答案

你需要说 tkinter,那些 "One""Two" 等是做什么用的。

Button(f, text="One")
Label(wn, text="This is my label!")

要回答为什么需要它,您应该检查函数和参数在 python 中的工作方式。

此外,您可能想要打包您的 Frame,因为它上面的所有按钮都可以使用 "left" 而不是 tkinter.LEFT

关于Python-属性错误: 'str' object has no attribute 'items' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31355904/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com