Tkinter showinfo python 3

I am trying to show an info window using

tkinter.messagebox.showinfo("info", "message") 

However, I get an error when using from tkinter import *

The problem is resolved if I also have import tkinter.messagebox

So I'm confused. Isn't it supposed from tkinter import * import everything inside tkinter ?

+6
source share
3 answers
 from tkinter import * from tkinter import messagebox root = Tk() root.title("test") root.geometry("300x300") app = Frame(root) app.grid() button1 = Button(app, text = " exit " , width=2, command=exit) button1.grid(padx=110, pady=80) def dialog(): var = messagebox.showinfo("test" , "hoi, dit is een test als je dit leest is het gelukt") button2 = Button(app, text = " uitleg " , width=4, command=dialog) button2.grid() root.mainloop(3) 

you just import the message box from tkinter and you create a message box (for example) showinfo ("test", "blablablabla")

+4
source

If you use the format from module import x , you are not prefixing the imported resources with the module. Therefore try

 messagebox.showinfo("info", "message") 

If you import like this: import tkinter.messagebox , you reference it with the module, so you will not get an error in this case.

+3
source

You can also try this method to access the messagebox method messagebox

 import tkinter as tk tk.messagebox.showinfo("info name","This is a Test") 
+1
source

Source: https://habr.com/ru/post/971335/


All Articles