#c://python25//env python
#-*-coding:UTF8-*-
from Tkinter import *
import os
class Dialog(Toplevel):
def __init__(self,parent,title=None):
Toplevel.__init__(self,parent)
self.transient(parent)
if title:
self.title(title)
self.parent=parent
self.result=None
self.body=Frame(self)
self.inital_focus=self.body(self.body)
self.body.pack(padx=5,pady=5)
self.buttonbox()
self.grab_set()
if not self.inital_focus:
self.inital_focus=self
self.protocol("WM_DELETE_WINDOW",self.cancel)
self.geometry("+%d+%d"%(parent.winfo_rootx()+5,parent.winfo_rooty()+50))
self.inital_focus.focus_set()
self.wait_window(self)
#结构钩子
def body(self,master):
#创建一个对话框,返回已有的框架
#初始化焦点,
Label(master,text="第一:").grid(row=0)
Label(master,text="第二:").grid(row=1)
self.e1=Entry(master)
self.e2=Entry(master)
self.e1.grid(row=0,column=1)
self.e2.grid(row=1,colunm=1)
return self.e1
def buttonbox(self):
#增加标准按钮
#标准按钮
box=Frame(self)
w=Button(box,text="确定",width=10,command=self.ok,default=ACTIVE)
w.pack(side=LEFT,padx=5,pady=5)
w=Button(box,text="取消",width=10,command=self.cancel)
w.pack(side=LEFT,padx=5,pady=5)
self.bind("&It;Return>",self.ok)
self.bind("&It;Escape>",self.cancel)
box.pack()
def ok(self,event=None):
if not self.validate():
self.inital_focus.focus_set()
return
self.withdraw()
self.update_idletasks()
self.apply()
self.cancel()
def cancel(self,event=None):
#把 焦点还原父窗口
self.parent.focus_set()
self.destroy()
#命令钩子
def validate(self):
return 1
def apply(self):
first=string.atoi(self.e1.get())
second=string.atoi(self.e2.get())
print first,second
root=Tk()
r=Dialog(root,title='测试')
r.mainloop()
有这个报错,
Traceback (most recent call last):
File "C:\Documents and Settings\Administrator.ZENGLEO\桌面\a.py", line 101, in <module>
r=Dialog(root,title='娴嬭瘯')
File "C:\Documents and Settings\Administrator.ZENGLEO\桌面\a.py", line 22, in __init__
self.inital_focus=self.body(self.body)
AttributeError: Frame instance has no __call__ method
能不能告诉我是为什么啊?