我收到帖子标题中提到的错误我真的只是希望这个工作.一段时间以来一直在研究这个问题,这令人沮丧.我的最终目标是获得可变数据文本,chkvar和v的值.
感谢任何能够回复并提供帮助的人!
#!C:/Python27/python.exe
from Tkinter import *
import ImageTk, Image
root = Tk()
root.title('HADOUKEN!')
def killwindow():
root.destroy()
text = Text(root, height=16, width=40)
scroll = Scrollbar(root, command=text.yview)
text.configure(yscrollcommand=scroll.set)
text.grid(sticky=E)
scroll.grid(row=0,column=1,sticky='ns')
text.focus()
chkvar = IntVar()
chkvar.set(0)
c = Checkbutton(root, text="CaseIt", variable=chkvar)
c.grid(row=1,column=0,sticky=W)
v = ""
radio1 = Radiobutton(root, text="Src", variable=v, value=1)
radio1.grid(row=1,column=0)
radio1.focus()
radio2 = Radiobutton(root, text="Dst", variable=v, value=2)
radio2.grid(row=2,column=0)
b1 = Button(root, text="Submit", command=killwindow)
b1.grid(row=1, column=2)
img = ImageTk.PhotoImage(Image.open("Hadoken.gif"))
panel = Label(root, image = img)
panel.grid(row=0, column=2)
root.mainloop()
tk1 = text.get(text)
tk2 = chkvar.get(chkvar)
tk3 = v.get(v)
print tk1
print tk2
print tk3
Run Code Online (Sandbox Code Playgroud)
一旦mainloop退出,小部件不再存在.当您这样做时text.get(text),您正在尝试访问已删除的小部件.在主窗口被销毁后,Tkinter的设计不允许您访问小部件.
快速解决方案是修改killwindow以在破坏窗口之前获取值,并将它们存储在mainloop退出后可以访问的全局变量中.
| 归档时间: |
|
| 查看次数: |
5272 次 |
| 最近记录: |