omar wael omar wael - 3 months ago 20
Python Question

remove the screen in back of the Tkinter message box

I want to show amessage box, but without the menu behind it in Python. This is my code:

import Tkinter, tkFileDialog ,tkMessageBox
from fileManagerModule import fileManager
def load():
global myFile,flag,msg
flag=True
options = {}
options["title"] = "choose a text File"
options['initialdir'] = '~/'
fileName = tkFileDialog.askopenfilename(**options)
myFile = fileManager(fileName)
myText.delete("1.0", Tkinter.END)
try:
line = myFile.readFromFile()
myText.insert("1.0", line)
except:
msg=Tkinter.Tk()
msg=tkMessageBox.showerror("Error","please choose file to load")


screenshot

Answer

You can use the withdraw() function to remove the window being displayed in the background to just show the dialog box only.

try this:

import Tkinter, tkFileDialog ,tkMessageBox
from fileManagerModule import fileManager
def load():
    global myFile,flag,msg
    flag=True
    options = {}
    options["title"] = "choose a text File"
    options['initialdir'] = '~/'    
    fileName = tkFileDialog.askopenfilename(**options)
    myFile = fileManager(fileName)
    myText.delete("1.0", Tkinter.END)
    try:
        line = myFile.readFromFile()
        myText.insert("1.0", line)
    except:
        msg=Tkinter.Tk()

        msg.withdraw()

        msg=tkMessageBox.showerror("Error","please choose file to load")