Search code examples
pythonuser-interfacetkinterpython-3.5

Python Tkinter small window pops up momentarily before main window


Hello I am making a Python Tkinter GUI program but as I was making it I noticed that a small Tkinter window pops up then closes before the main window pops up. It is very distracting and obviously something that you would have in a professional piece of software. Here is an example of the problem:

from tkinter import *

app = Tk()
app.title("My GUI")
app.iconbitmap(r"C:\Program Files (x86)\Notepad++\Files\journalicon.ico")
app.resizable(0,0)

button = Button(text = "Text")
button.pack()

app.mainloop()

The iconbitmap option was something I found from another stack overflow page and used it. If you know of a better option I would appreciate the help. I am quite lost and would really appreciate any answers.


Solution

  • Try this:

    app = Tk()
    app.title("My GUI")
    app.iconbitmap(app, "C:\Program Files (x86)\Notepad++\Files\icon.ico")
    app.resizable(0,0)
    
    app.mainloop()
    

    You let tkinter know that the definition for things inside the window have stopped by calling mainloop. I have defined the window for the iconbitmap when it is called, using "(app, .."

    Hope this helps!