0

我制作了自己的按钮(所以我使用了图像),它就像装饰一样,它必须保持在原位但也不能点击,当我将它设置为"disabled'状态时它会得到一个非常丑陋的过滤器:

在此处输入图像描述

如果没有那个丑陋的过滤器,我怎样才能让它无法点击?

4

1 回答 1

0

这是以前代码的改进版本。

它将暂时删除标题栏,并在必要时将其恢复。

F1现在通过充当切换开关来控制标题栏的可见性。

现在可以随时拿起和移动Button-1窗口Motion

退出键或 Alt F4 将关闭窗口。

import tkinter as tk

root = tk.Tk()

def showhide( ev ):
    ev.widget.lift()
    if root.overrideredirect(None):
        ev.widget.overrideredirect( 0 )
    else:
        ev.widget.overrideredirect( 1 )

def drag( ev = None ):
    global xpos, ypos, dragx, dragy, wide, high
    if root.overrideredirect(None):
        if dragx == 0 and dragy == 0:
            dragx, dragy = ev.x, ev.y
        xpos = xpos + ev.x - dragx
        ypos = ypos + ev.y - dragy
        if xpos < 0:  Xpos = 0
        if ypos < 0:  Ypos = 0
        xmax = root.winfo_screenwidth() - wide
        ymax = root .winfo_screenheight() - high
        if xpos > xmax:  xpos = xmax
        if ypos > ymax:  ypos = ymax
        root.geometry( f'+{xpos}+{ypos}')

def clear( ev ):
    global dragx, dragy
    dragx, dragy = 0, 0

def closer( ev = None ):
    root.destroy()

label = tk.Label(
    root,
    text = """Press F1 to hide or show window Title bar
Press Escape key or Alt-F4 to close program
You may now Pickup and drag window around

This movement modification thanks to @titoo

""",
    justify = "left", anchor = "center",
          width = 40, height = 20)
label.pack()

root.resizable( False, False )
root.update()

root.protocol( "WM_DELETE_WINDOW", closer )
root.bind( "<Escape>", closer )

dragx, dragy = 0, 0
xpos, ypos = root.winfo_x(), root.winfo_y()
wide, high = root.winfo_width(), root.winfo_height()

root.bind( "<F1>", showhide )
root.bind( '<B1-Motion>', drag )
root.bind( '<ButtonRelease-1>', clear )

drag( )

root.mainloop()
于 2021-08-05T02:15:20.107 回答