<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
On 08/13/2011 04:49 PM, Peter Otten wrote:
<blockquote cite="mid:j26nvk$t7c$1@dough.gmane.org" type="cite">
<pre wrap="">brandon w wrote:
</pre>
<blockquote type="cite">
<pre wrap="">I have tried to follow the tutorial I found here:
Python 2.7 Tutorial
<a class="moz-txt-link-freetext" href="http://www.youtube.com/watch?v=uh6AdDX7K7U">http://www.youtube.com/watch?v=uh6AdDX7K7U</a>
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?
</pre>
</blockquote>
<pre wrap="">
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>
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">import tkMessageBox
dir(tkMessageBox)
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">['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']
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">tkMessageBox.askyesno("does that help you?")
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap="">True
Of course you could also consult some documentation. I usually google for
tkinter new mexico.
<a class="moz-txt-link-freetext" href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/dialogs.html#tkMessageBox">http://infohost.nmt.edu/tcc/help/pubs/tkinter/dialogs.html#tkMessageBox</a>
</pre>
<blockquote type="cite">
<pre wrap="">I am running Python 2.6.6. It may be a little older and not have the
messagebox module.
</pre>
</blockquote>
<pre wrap="">
I think tkMessageBox has been moved to tkinter.messagebox in Python 3.
_______________________________________________
Tutor maillist - <a class="moz-txt-link-abbreviated" href="mailto:Tutor@python.org">Tutor@python.org</a>
To unsubscribe or change subscription options:
<a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a>
</pre>
</blockquote>
I have tried # 1. with another command but all I get is an error
messages.<br>
<font color="#ff6600"><br>
<font color="#330033">$ python -c 'import time, os; print
os.path.dirname(time.__doc__)'</font></font> <font color="#cc0000">#
This one gave no output.</font><br>
<br>
$ python -c 'import time, strftime, os; print
os.path.dirname(strftime.__doc__)' <br>
<font color="#ff0000">Traceback (most recent call last):<br>
File "<string>", line 1, in <module><br>
ImportError: No module named strftime</font><br>
<br>
$ python -c 'import os; from time import strftime; print
os.path.dirname(strftime.__file__)'<br>
<font color="#ff0000">Traceback (most recent call last):<br>
File "<string>", line 1, in <module><br>
AttributeError: 'builtin_function_or_method' object has no attribute
'__file__'</font><br>
<br>
$ python -c 'import time, os; print os.path.dirname(time.__file__)'<br>
<font color="#cc0000">Traceback (most recent call last):<br>
File "<string>", line 1, in <module><br>
File "/usr/lib/python2.6/posixpath.py", line 119, in dirname<br>
i = p.rfind('/') + 1<br>
AttributeError: 'NoneType' object has no attribute 'rfind'</font><br>
<br>
$ python -c 'import time, os; print os.path.dirname(time.__package__)'<br>
<font color="#cc0000">more errors</font><br>
<br>
I am obviously doing something wrong.<br>
<br>
<br>
</body>
</html>