Reputation: 3891
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.
Upvotes: 1
Views: 3093
Reputation: 1446
I had the same issue, it's caused by a delay in executing code before the window is drawn. The solution is to set the window size before doing anything else. Move app.resizable(0,0) up, and the problem goes away.
from tkinter import *
app = Tk()
app.resizable(0,0)
app.title("My GUI")
app.iconbitmap(r"C:\some_random_icon.ico")
button = Button(text = "Text")
button.pack()
app.mainloop()
In my case I had the self.geometry() command defined too low down, this should also be executed immediately after you initiate your app.
import tkinter as tk
app = tk.Tk()
app.geometry('200x100')
#... add rest of code here.
Upvotes: 0
Reputation: 635
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!
Upvotes: 1