【发布时间】:2017-06-08 17:46:00
【问题描述】:
我只与 tkinter 合作了几个月。我写了一些代码 使用“框架”和“网格”没有问题。我刚开始尝试使用“Pack” 我遇到了这个错误的问题:AttributeError: 'Frame' object has no attribute 'frame1'。
我做错了什么?
代码:
from tkinter import *
root=Tk()
root.title("Spin Box")
root.resizable(0,0)
frame1=Frame(root).frame1.pack(side=LEFT, fill=BOTH)
frame2=Frame(root).frame2.pack(side=RIGHT, fill=BOTH)
labe11=Label(frame1).labeL1.pack()
label2=Label(frame2, text="How many Ticket?", font="bold").label2.pack()
button1=Button(frame2, text="Get Tickets", font="bold", command=runcode).button1.pack()
button2=Button(frame2, text=" Close ", font="bold", command=subwin.destroy).button2.pack()
sp1=Spinbox(frame2, from_='1', to='5', bd=2, bg="white", state='readonly', relief=SUNKEN)
sp1.pack()
root.mainloop()
追溯:
Traceback(最近一次调用最后一次): 文件“./tkerr3.py”,第 7 行,在 frame1=Frame(root).frame1.pack(side=LEFT, fill=BOTH) AttributeError: 'Frame' 对象没有属性 'frame1'
【问题讨论】:
-
先把
labeL1改成label1