Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Tkinter- small window pops up momentarily before main window

Tags:

python

tkinter

I'm using tkinter to create a simple window. When I run python mainwindow.py, a small window pops up briefly and closes right before main window (mostly to the top left corner of the screen). Here's a GIF demonstrating it:

wtf

Here's the code I've used (mainwindow.py):

import tkinter as tk


def center(win, width, height):
    win.update_idletasks()
    x = (win.winfo_screenwidth() // 2) - (width // 2)
    y = (win.winfo_screenheight() // 2) - (height // 2)
    win.geometry(f'{width}x{height}+{x}+{y}')


def main():
    width = 500
    height = 500

    main_window = tk.Tk()
    main_window.title('7Watchlist DataGrabber')
    main_window.iconbitmap(main_window, r'images\icon.ico')
    center(main_window, width, height)
    main_window.resizable(False, False)

    main_window.mainloop()


if __name__ == "__main__":
    main()

There is an exactly similar question with an accepted answer. On it, OP says in the comments:

I think I finally figured out the root of the problem. [...] So instead of my original code app.iconbitmap(r"C:\Program Files (x86)\Notepad++\Files\journalicon.ico") you need to do app.iconbitmap(app, r"C:\Program Files (x86)\Notepad++\Files\journalicon.ico") [...]

And the accepted answer seems to indicate the same thing:

  • To replace app.iconbitmap(r'address') with app.iconbitmap(app, r'address').

But my code already uses iconbitmap in this format. So my question is: How can I get rid of this small window?

like image 283
Amir Shabani Avatar asked Apr 25 '26 00:04

Amir Shabani


1 Answers

I just removed the bitmap = main_window from main_window.wm_iconbitmap(bitmap=None, default=None) and seems like it solved the problem, I only set the default parameter. Though I'm on Mac OS and iconbitmap doesn't properly work like the icon doesn't show.

Also I ran it with win.update_idletasks() and still don't see the small window but you can give it a try by removing it.

enter image description here

I hope this helped you.

like image 77
Saad Avatar answered Apr 27 '26 12:04

Saad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!