Tkinter, how to use the same script in win and llinux without the window icon getting in the way

Asked

Viewed 61 times

0

I’ve been writing some scripts in Win VS and when I switched to Linux, I came across the following problem: When I use an image as a window icon in Linux (which does not have it), the script does not run.

How could I "detect" the OS so that it does not use this feature in Linux distributions, avoiding error?

Example:

from tkinter import *

win = Tk()
win.title("teste")
#problema - mas e no Linux?
win.iconbitmap("logo.ico")

winLabel = Label(win, text="Isso é um teste").place(x=50, y=50)
win.resizable(width=False, height=False)
win.geometry("200x200")
win.mainloop()

1 answer

-1

Try using exception treatment by replacing:

win.iconbitmap("logo.ico")

for:

try:
    win.iconbitmap("logo.ico")
except:
    pass

Browser other questions tagged

You are not signed in. Login or sign up in order to post.