python - 任务栏中的 Tkinter 窗口具有 Overdirect True

标签 python tkinter

我想在窗口未最小化时在任务栏中显示我的 tkinter 窗口图标( .overrideredirect 设置为 True ),我看到了其他问题,例如 Make tkinter Window appear in the taskbar Tkinter, Windows: How to view window in windows task bar which has no title bar? 但两者都有包含 ctypes 的答案模块,我想知道是否有一种更简单的方法可以做到这一点,也许这也适用于其他操作系统。

这是图形用户界面

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()

最佳答案

你可以尝试: root.iconbitmap("_full_path_to_icon_file") 例如:root.iconbitmap("icon.ico") 或者:root.icontbitmap("_relative_path")。 我所说的相对路径是指图标图像是否存在于当前文件夹中而不是其他地方。

关于python - 任务栏中的 Tkinter 窗口具有 Overdirect True,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55670630/

相关文章:

python - 如何在 $WORKON_HOME 之外的版本控制下保持 virtualenvwrapper Hook

python - Django 将自定义表单参数传递给 Formset

python - HyperVolume 函数在 Python 3 中不起作用

python - 使用 Python 和 Tkinter 创建温度程序

python - 如何设置按钮的大小(以像素为单位)- python

python - 在二维 Python 数组中查找元素

python - python3.5中使用split函数

python - 我可以为 tkinter 图标使用哪些文件格式?

python - 如何使用 matplotlib 在 tkinter 中制作 donut chart 图

python - 如何将文件位置存储到条目小部件中 - Tkinter