Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Learning tkinter

43 views
Skip to first unread message

Grant Edwards

unread,
May 18, 2023, 9:16:28 AM5/18/23
to
On 2023-05-12, Rob Cliffe via Python-list <pytho...@python.org> wrote:
>
> Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32
> bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import tkinter
> >>> tkinter.messagebox
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: module 'tkinter' has no attribute 'messagebox'
> >>>

$ python
Python 3.11.3 (main, May 8 2023, 09:00:54) [GCC 12.2.1 20230428] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> from tkinter import messagebox
>>> messagebox
<module 'tkinter.messagebox' from '/usr/lib/python3.11/tkinter/messagebox.py'>
>>>


> Why is this?

Dunno.

Oscar Benjamin

unread,
May 18, 2023, 9:44:55 AM5/18/23
to
On Thu, 18 May 2023 at 10:16, Rob Cliffe via Python-list
<pytho...@python.org> wrote:
>
> I am trying to learn tkinter.
> Several examples on the internet refer to a messagebox class
> (tkinter.messagebox).
> But:
>
> Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32
> bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import tkinter
> >>> tkinter.messagebox
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: module 'tkinter' has no attribute 'messagebox'
> >>>
>
> Why is this?

Do you have a file called tkinter.py in the current directory?

--
Oscar

Chris Angelico

unread,
May 18, 2023, 10:00:39 AM5/18/23
to
On Thu, 18 May 2023 at 19:15, Rob Cliffe via Python-list
<pytho...@python.org> wrote:
>
> I am trying to learn tkinter.
> Several examples on the internet refer to a messagebox class
> (tkinter.messagebox).
> But:
>
> Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32
> bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import tkinter
> >>> tkinter.messagebox
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: module 'tkinter' has no attribute 'messagebox'
> >>>
>
> Why is this?

Is it possible that you've created a tkinter.py for your own tinkering?

ChrisA

Jim Schwartz

unread,
May 18, 2023, 10:53:04 AM5/18/23
to
This works for me. Hope it helps.

from tkinter import messagebox

messagebox.showerror("Hi", f"Hello World")

-----Original Message-----
From: Python-list <python-list-bounces+jschwar=sbcglo...@python.org> On Behalf Of Rob Cliffe via Python-list
Sent: Friday, May 12, 2023 3:55 AM
To: Python <pytho...@python.org>
Subject: Learning tkinter

I am trying to learn tkinter.
Several examples on the internet refer to a messagebox class (tkinter.messagebox).
But:

Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> tkinter.messagebox
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tkinter' has no attribute 'messagebox'
>>>

Why is this?
TIA
Rob Cliffe
--
https://mail.python.org/mailman/listinfo/python-list

Thomas Passin

unread,
May 18, 2023, 11:50:35 AM5/18/23
to
On 5/18/2023 9:13 AM, Grant Edwards wrote:
> On 2023-05-12, Rob Cliffe via Python-list <pytho...@python.org> wrote:
>>
>> Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32
>> bit (Intel)] on win32
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> import tkinter
>>>>> tkinter.messagebox
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> AttributeError: module 'tkinter' has no attribute 'messagebox'
>>>>>
>
> $ python
> Python 3.11.3 (main, May 8 2023, 09:00:54) [GCC 12.2.1 20230428] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import tkinter
>>>> from tkinter import messagebox
>>>> messagebox
> <module 'tkinter.messagebox' from '/usr/lib/python3.11/tkinter/messagebox.py'>
>>>>
>
>
>> Why is this?
>
> Dunno.

tkinter is a package, messagebox is a module within the tkinter package.
the messagebox module has some functions, such as showinfo(). You *can*
import those functions using "dot" expressions:

>>> from tkinter.messagebox import showinfo
<function showinfo at 0x0000021CED0634C0>

You can also import the entire module using the "dot" syntax:

>>> import tkinter.messagebox
>>> messagebox.showinfo
<function showinfo at 0x0000021CED0634C0>

Whether you can directly ask for tkinter.messagebox depends on whether
it's been defined or imported in tkinter/__init__.py.



Mats Wichmann

unread,
May 18, 2023, 12:42:59 PM5/18/23
to
On 5/18/23 08:50, Jim Schwartz wrote:
> This works for me. Hope it helps.
>
> from tkinter import messagebox
>
> messagebox.showerror("Hi", f"Hello World")

It's probably instructive that IDLE always brings it in this way.

Lib/idlelib/config_key.py:from tkinter import messagebox
Lib/idlelib/configdialog.py:from tkinter import messagebox
Lib/idlelib/editor.py:from tkinter import messagebox
... etc


MRAB

unread,
May 18, 2023, 1:36:18 PM5/18/23
to
On 2023-05-12 09:55, Rob Cliffe via Python-list wrote:
> I am trying to learn tkinter.
> Several examples on the internet refer to a messagebox class
> (tkinter.messagebox).
> But:
>
> Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32
> bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import tkinter
> >>> tkinter.messagebox
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: module 'tkinter' has no attribute 'messagebox'
> >>>
>
> Why is this?

It's a submodule of tkinter:

>>> import tkinter.messagebox as mb
>>> mb.showinfo
<function showinfo at 0x000001994C7F2020>

risky sibam

unread,
May 18, 2023, 5:28:15 PM5/18/23
to
0 new messages