我正在尝试创建一个对话框,该对话框将从弹出对话框中获取社会安全号码(或模拟输入),但是当我尝试时收到错误消息,指出该类没有该属性。这是代码:
from Tkinter import *
class App:
def __init__(self, master):
b = Button(text="Click for social dialog", command=self.getSocial)
b.grid(row=0, column=0)
def getSocial(self):
d = socialDialog(root)
print d.social
class socialDialog:
def __init__(self, master):
self.top = Toplevel()
Label(self.top, text='Social Security #: ').grid(row=0, column=0)
self.entry = Entry(self.top)
self.entry.grid(row=0, column=1)
self.entry.focus_set()
self.top.bind('<Key>', self.formatData)
self.top.bind('<Return>', self.ok)
def formatData(self, master):
currentData = self.entry.get()
if len(currentData) == 3:
self.entry.insert(3, '-')
elif len(currentData) == 6:
self.entry.insert(6, '-')
elif len(currentData) > 11:
self.entry.delete(-1, END)
def ok(self, master):
self.social = self.entry.get()
self.top.destroy()
root = Tk()
app = App(root)
root.mainloop()