0

Issue description: Please see following two example of Code A and Code B.

  1. Code A:

    from tkinter import messagebox
    messagebox.showinfo("Hello ")
    
  2. Code B:

    from tkinter import *
    tkinter.messagebox.showinfo("Hello ")
    

Question : Why Code B doesn't work?

(I do not want to get confused on using short form tk,I am ok writing tkinter)

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Vi sharma
  • 5
  • 3
  • Still not clear why code B cant work, can u pls elaborate only on the code above, will appreciate it.Thank you..Vi – Vi sharma Dec 21 '20 at 22:38

1 Answers1

1

The first is correct for the messagebox.

As with many python packages, not all functionality is automatically imported. Some, such as the messagebox and font modules, must be explicitly imported.

In the second case, you should not use wildcard imports. Even though a lot of tkinter tutorials import tkinter this way, PEP8 is the standard and it discourages wildcard imports.

While it will indeed import many of the tkinter classes and variables, it still won't import the messagebox module.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • why sir it will not import message box module, since its "*", I am trying to find how to make code B work, just for understanding (I will not use that practice just to understand the process) – Vi sharma Dec 21 '20 at 22:37
  • @Visharma: like the answer says, "not all functionality is automatically imported". That's just how some packages work. "code B" will never work. You must import `messagebox` separately. – Bryan Oakley Dec 21 '20 at 23:18
  • Thx for reply sir.. best Vi – Vi sharma Dec 22 '20 at 02:40