[Tutor] tkinter and messagebox

Clyde Wilson clydew at clydew.org
Sat Mar 30 01:00:56 CET 2013


The following code works fine under IDLE but errors when run as a standalone:
 
from tkinter import *
root=Tk()
main=Frame(root)
main.grid()
def doit():
    messagebox.showinfo("Hello")
btn1=Button(main,width=10,text="In")
btn1.grid()
lbl1=Label(main)
lbl1.grid()
btn2=Button(main,width=10,text="Out",command=doit)
btn2.grid()
lbl2=Label(main)
lbl2.grid()
root.mainloop()
 
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python33\lib\tkinter\__init__.py", line 1442, in __call__
    return self.func(*args)
  File "C:\Users\Wilson\Documents\Old Documents\My Stuff\Python Pgms\temp.py", l
ine 6, in doit
    messagebox.showinfo("Hello")
NameError: global name 'messagebox' is not defined
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130329/c7e73083/attachment.html>


More information about the Tutor mailing list