2

I want to show my tkinter window icon in the taskbar when the window is not minimized ( the .overrideredirect is set to True ), i saw others questions like Make tkinter Window appear in the taskbar and Tkinter, Windows: How to view window in windows task bar which has no title bar? but both have answers that includes the ctypes module, i was wondering if there is a simpler way for do this and maybe that works on other os too.

Here is the gui

from tkinter import *
import time
import os

x, y = 0, 0


def startMove(event):
    global x, y
    print(event.x_root, event.x, borderFrame.winfo_rootx())
    x = event.x
    y = event.y
def stopMove(event):
    global x, y
    x = None
    y = None
def moving(event):
    global x, y
    x_ = (event.x_root - x)
    y_ = (event.y_root - y)
    root.geometry("+%s+%s" % (x_, y_))
def frame_mapped(e):
    print(e)
    root.update_idletasks()
    root.overrideredirect(True)
    root.state('normal')
def minimize(event):
    root.update_idletasks()
    root.overrideredirect(False)
    #root.state('withdrawn')
    root.state('iconic')
def exitProgram(event):
    os._exit(0)
def hover(event):
    event.widget.config(bg="red")
def unhover(event):
    event.widget.config(bg="white")
def hoverMin(event):
    event.widget.config(bg="grey")
def unHoverMin(event):
    event.widget.config(bg="white")


root = Tk()
root.title("Draggable Root")
root.geometry("500x600")
root.overrideredirect(True)

borderFrame = Frame(root, width=500, height=600, bg="white")
borderFrame.pack_propagate(False)
borderFrame.pack(side=TOP)

holderFrame = Frame(borderFrame, width=500, height=570, bg="grey62")
holderFrame.pack_propagate(False)
holderFrame.pack(side=BOTTOM)

close = Label(root, font=("Arial", 11), bg="white", anchor=CENTER, text="X", cursor="hand2")
close.place(x=460, y=0, width=40, height=30)

min = Label(root, font=("Arial", 11), bg="white", anchor=CENTER, text="_", cursor="hand2")
min.place(x=420, y=0, width=40, height=30)

min.bind("<Enter>", hoverMin)
min.bind("<Leave>", unHoverMin)
min.bind("<Button-1>", minimize)
close.bind("<Enter>", hover)
close.bind("<Leave>", unhover)
close.bind("<Button-1>", exitProgram)
borderFrame.bind("<Button-1>", startMove)
borderFrame.bind("<ButtonRelease-1>", stopMove)
borderFrame.bind("<B1-Motion>", moving)
borderFrame.bind("<Map>", frame_mapped)
root.mainloop()
Mat.C
  • 1,379
  • 2
  • 21
  • 43

2 Answers2

0

If you are trying to get icon on alt-Tab then I can't really test that as I've Mac but it is showing in my command-tab which is pretty much same as alt-tab.

Sample Image

The only thing I change to get the window visible on my system is

root.overrideredirect(True)
root.overrideredirect(False)

As on Mac just root.overrideredirect(True) hides the window

Saad
  • 3,340
  • 2
  • 10
  • 32
  • i don't want to change the tkinter icon, i wanto to show the icon in the taskbar when the window is not minimized – Mat.C Apr 14 '19 at 10:01
  • I changed my answer, but I'm not sure if this will help you. – Saad Apr 14 '19 at 10:28
0

You could try: root.iconbitmap("_full_path_to_icon_file") Eg: root.iconbitmap("icon.ico") Or:root.icontbitmap("_relative_path"). By relative path I mean if the icon image is present in your current folder and not somewhere else.

Rahul
  • 576
  • 1
  • 5
  • 9
  • i don't want to change the tkinter icon, i wanto to show the icon in the taskbar when the window is not minimized – Mat.C Apr 14 '19 at 10:01