我正在关注第 31 页和第 32 页上的教程http://www.ittc.ku.edu/~niehaus/classes/448-s04/448-standard/tkinter-intro.pdf。
我得到两个窗口,一个带有确定和取消按钮以及两个输入框,另一个是空白的。当我单击“确定”或“取消”时,该窗口会消失,但另一个空白窗口会冻结,我什至无法关闭。关闭它的唯一方法是关闭命令提示符。
运行时出现以下错误。
first = string.atoi(self.e1.get())
NameError: global name 'string' is not defined
如我的评论所示,我调整了 dialog2.py。tkSimpleDialog.py 根本没有改变(上面链接的第 31 页)
# File: dialog2.py
import tkSimpleDialog #added this
import os #added this
from Tkinter import * #added this
class MyDialog(tkSimpleDialog.Dialog):
def body(self, master):
Label(master, text="First:").grid(row=0)
Label(master, text="Second:").grid(row=1)
self.e1 = Entry(master)
self.e2 = Entry(master)
self.e1.grid(row=0, column=1)
self.e2.grid(row=1, column=1)
return self.e1 # initial focus
def apply(self):
first = string.atoi(self.e1.get())
second = string.atoi(self.e2.get())
print first, second # or something
root = Tk() #added this
d = MyDialog(root) #added this