2016-08-27 42 views
-1

我想顯示一個消息框,但在Python後面沒有父窗口。這是我的代碼:刪除Tkinter消息框背面的屏幕

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

+0

請分享你的整個代碼:) –

+0

@NehalJWani代碼太大,我沒有細節 –

+0

不顯示_all_你的代碼,只需創建一個完整的,工作示例。您只需添加更多行(http://stackoverflow.com/help/mcve)。但首先,請嘗試搜索此網站並閱讀一些文檔。這些信息在許多地方都可用。 –

回答

1

可以使用withdraw()功能刪除window顯示在後臺只只顯示該對話框。

試試這個:

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")