tkinter showinfo python 3

49,340

Solution 1

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 messagebox from tkinter and you do messagebox.(for example)showinfo("test" , "blablablabla")

Solution 2

If you use the from module import x format, you don't prefix the imported resources with the module. So try

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

If you import like this: import tkinter.messagebox you reference it with the module, which is why you don't get an error in that case.

Solution 3

from tkinter import * will load Tkinter's __init__.py which doesn't include messagebox, so to solve it we do import tkinter.messagebox which loads messagebox's __init__.py.

Solution 4

Can also try this method to access the messagebox method

import tkinter as tk

tk.messagebox.showinfo("info name","This is a Test")
Share:
49,340
mihota
Author by

mihota

I’d rather trust and regret than doubt and regret.

Updated on July 09, 2022

Comments

  • mihota
    mihota almost 2 years

    I am trying to show an info window by using

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

    However, I am getting error while using from tkinter import *

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

    So I am confused. Isn't from tkinter import * is supposed to import everything inside tkinter?