On 08/13/2011 04:49 PM, Peter Otten wrote:
brandon w wrote:
I have tried to follow the tutorial I found here:
Python 2.7 Tutorial
http://www.youtube.com/watch?v=uh6AdDX7K7U
This is what I have done so far:
#!/usr/bin/python
from Tkinter import *
import Tkinter.MessageBox
myapp = Tk()
myapp.title("This is the gui title")
myapp.geometry("500x500+600+600")
myapp.mainloop()
I run it like this:
$ python tktest.py
I am getting the error message:
Traceback (most recent call last):
File "tkwindow.py", line 12, in<module>
import Tkinter.MessageBox
ImportError: No module named MessageBox
And then after changing the uppercase to lowercase this:
Traceback (most recent call last):
File "tkwindow.py", line 12, in<module>
import Tkinter.messagebox
ImportError: No module named messagebox
How do I find the modules in Tkinter?
The simplest approach is probably to explore your file system:
Step 1: where's Tkinter?
$ python -c 'import Tkinter, os; print os.path.dirname(Tkinter.__file__)'
/usr/lib/python2.6/lib-tk
Step 2: explore the neighbourhood
$ find `python -c 'import Tkinter, os; print
os.path.dirname(Tkinter.__file__)'` -iname '*messagebox*.py'
/usr/lib/python2.6/lib-tk/tkMessageBox.py
Step 3: we have a candidate; let's verify:
$ python
<snip>
import tkMessageBox
dir(tkMessageBox)
['ABORT', 'ABORTRETRYIGNORE', 'CANCEL', 'Dialog', 'ERROR', 'IGNORE', 'INFO',
'Message', 'NO', 'OK', 'OKCANCEL', 'QUESTION', 'RETRY', 'RETRYCANCEL',
'WARNING', 'YES', 'YESNO', 'YESNOCANCEL', '__builtins__', '__doc__',
'__file__', '__name__', '__package__', '_show', 'askokcancel',
'askquestion', 'askretrycancel', 'askyesno', 'askyesnocancel', 'showerror',
'showinfo', 'showwarning']
tkMessageBox.askyesno("does that help you?")
True
Of course you could also consult some documentation. I usually google for
tkinter new mexico.
http://infohost.nmt.edu/tcc/help/pubs/tkinter/dialogs.html#tkMessageBox
I am running Python 2.6.6. It may be a little older and not have the
messagebox module.
I think tkMessageBox has been moved to tkinter.messagebox in Python 3.
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
I have tried # 1. with another command but all I get is an error messages.
$ python -c 'import time, os; print os.path.dirname(time.__doc__)' #
This one gave no output.
$ python -c 'import time, strftime, os; print
os.path.dirname(strftime.__doc__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named strftime
$ python -c 'import os; from time import strftime; print
os.path.dirname(strftime.__file__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'builtin_function_or_method' object has no attribute
'__file__'
$ python -c 'import time, os; print os.path.dirname(time.__file__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.6/posixpath.py", line 119, in dirname
i = p.rfind('/') + 1
AttributeError: 'NoneType' object has no attribute 'rfind'
$ python -c 'import time, os; print os.path.dirname(time.__package__)'
more errors
I am obviously doing something wrong.
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor