Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tkinter showinfo python 3

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?

like image 586
mihota Avatar asked Jun 25 '14 10:06

mihota


People also ask

Does Python 3 come with Tkinter?

Tkinter is the de facto way in Python to create Graphical User Interfaces (GUIs). Installing Tkinter on Windows is as simple as installing Python 3. x since Tkinter is included in the Python 3 core.

How do you show error box in Python?

Build A Paint Program With TKinter and Python If you need to display the error messagebox in your application, you can use showerror("Title", "Error Message") method. This method can be invoked with the messagebox itself.

How do you make a pop up box in Tkinter?

Popup window in Tkinter can be created by defining the Toplevel(win) window. A Toplevel window manages to create a child window along with the parent window. It always opens above all the other windows defined in any application.


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

like image 175
josti Avatar answered Oct 08 '22 13:10

josti


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.

like image 45
Mattias Backman Avatar answered Oct 08 '22 11:10

Mattias Backman