Reputation: 2167
I'm following the tutorial found here on pages 31 and 32 http://www.ittc.ku.edu/~niehaus/classes/448-s04/448-standard/tkinter-intro.pdf .
I get two windows, one with OK and Cancel buttons and two entryboxes, and another that is blank. When I click OK or Cancel, that window disappears but the other blank window freezes up and I can't even close out. The only way to close it is by closing out of command prompt.
I'm getting the following error when I run it.
first = string.atoi(self.e1.get())
NameError: global name 'string' is not defined
I adjusted dialog2.py as shown in my comments. tkSimpleDialog.py is not changed at all (page 31 of the link above)
# 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
Upvotes: 1
Views: 279
Reputation: 310089
You need to import the string
module.
Although a better way to do this (without needing to import string) is to use the int
builtin. i.e. change it to:
first = int(self.e1.get())
etc.
I'm guessing the reference manual you're working through was created for a very old version of python ...
Upvotes: 4