• Re: Learning tkinter

    From Grant Edwards@21:1/5 to Rob Cliffe via Python-list on Thu May 18 06:13:52 2023
    On 2023-05-12, Rob Cliffe via Python-list <python-list@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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to Rob Cliffe via Python-list on Thu May 18 13:59:30 2023
    On 2023-05-12, Rob Cliffe via Python-list <python-list@python.org> wrote:
    import tkinter
    tkinter.messagebox

    (Sorry for this indirect response due to technical reasons!)

    The module "tkinter.messagebox" is an independent module within
    the package "tkinter", so one needs to import it separately:

    import tkinter.messagebox
    tkinter.messagebox.showinfo( "Example" )

    . If you want to hide the root window, add:

    import tkinter
    root = tkinter.Tk()
    root.withdraw()
    root.withdraw()

    . To properly learn tkinter, however, ignore the messagebox module
    during your first steps and start with:

    import tkinter
    root_window = tkinter.Tk()
    root_window.mainloop()

    as one of the most simple tkinter programs. Then add a label:

    import tkinter
    root_window = tkinter.Tk()
    label = tkinter.Label( root_window, text="Hello!" )
    label.pack()
    root_window.mainloop()

    . Read the part III "GUI Programming" in the book
    "Programming Python" by Mark Lutz!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Oscar Benjamin@21:1/5 to python-list@python.org on Thu May 18 14:44:18 2023
    On Thu, 18 May 2023 at 10:16, Rob Cliffe via Python-list <python-list@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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to python-list@python.org on Fri May 19 00:00:01 2023
    On Thu, 18 May 2023 at 19:15, Rob Cliffe via Python-list <python-list@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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jim Schwartz@21:1/5 to All on Thu May 18 09:50:38 2023
    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=sbcglobal.net@python.org> On Behalf Of Rob Cliffe via Python-list
    Sent: Friday, May 12, 2023 3:55 AM
    To: Python <python-list@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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to Grant Edwards on Thu May 18 11:48:29 2023
    On 5/18/2023 9:13 AM, Grant Edwards wrote:
    On 2023-05-12, Rob Cliffe via Python-list <python-list@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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mats Wichmann@21:1/5 to Jim Schwartz on Thu May 18 10:41:28 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MRAB@21:1/5 to Rob Cliffe via Python-list on Thu May 18 18:31:15 2023
    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>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From risky sibam@21:1/5 to All on Thu May 18 14:28:02 2023
    Pada Kamis, 18 Mei 2023 pukul 20.16.28 UTC+7, Grant Edwards menulis:
    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.
    https://budimulia.ac.id/mpo-play/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)