0

I am creating an image viewer. But, I don't know how to set the argument for iconbitmap.

I have tried bitmap, default but it says default is not defined.

def open_to_browse():
    global my_image
    mainframe1.filename = filedialog.askopenfilename(initialdir=home, title="Select a file", filetypes=(("*.png"),("*.jpeg")))
    my_label = tk.Label(mainframe1, text=mainframe1.filename)
    my_image = ImageTk.PhotoImage(Image.open(mainframe1.filename))
    my_image_label = tk.Label(image = my_image)

import os
import tkinter as tk
from tkinter import filedialog
from PIL import ImageTk
from PIL import Image

home = os.getcwd()
#print(home)

mainframe1 = tk.Tk()
mainframe1.title("Image Viewer")
mainframe1.iconbitmap(bitmap= "NoneType:None", default= "NoneType:None")

button = tk.Button(mainframe1, text="Open the file", command=open_to_browse)

my_label.grid(row=0, column=1, sticky=tk.W, pady=4)
button.grid(row=1, column=1, sticky=tk.W, pady=4)
my_image_label.grid(row=2, column=1, sticky=tk.W, pady=4)

mainframe1.mainloop()
stovfl
  • 14,998
  • 7
  • 24
  • 51
Ishita Katyal
  • 13
  • 1
  • 6

1 Answers1

0

Put in the full pathname. For example:

mainframe1.iconbitmap(r'c:\Python32\DLLs\py.ico')

or, keep icon in the same folder where your project script file is present

mainframe1.iconbitmap(r'py.ico')

Set bitmap for the iconified widget to BITMAP. Return the bitmap if None is given.

Under Windows, the DEFAULT parameter can be used to set the icon for the widget and any descendents that don't have an icon set explicitly. DEFAULT can be the relative path to a .ico file (example: root.iconbitmap(default='myicon.ico') ).

edit:

iconbitmap(bitmap=None)

Sets or gets the icon bitmap to use when this window is iconified. This method is ignored by some window managers (including Windows).

Under Windows, the default parameter can be used to set the icon for the widget and any descendents that don't have an icon set explicitly. default can be the relative path to a .ico file (example: root.iconbitmap(default='myicon.ico') ). See Tk documentation for more information.

If the -default flag is given, the icon is applied to all toplevel windows (existing and future) to which no other specific icon has yet been applied.

In addition to bitmap image types, a full path specification to any file which contains a valid Windows icon is also accepted (usually .ico or .icr files), or any file for which the shell has assigned an icon.

The iconbitmap function (or method, depending on the programming language) should be used to set a bitmap image to the window when the window is iconified.

On Windows you're allowed to set a full path specification to any file which contains a valid Windows icon is also accepted (usually .ico or .icr files), or any file for which the shell has assigned an icon.

ncica
  • 7,015
  • 1
  • 15
  • 37