0

I made my own button (so I'm using an image), it's just like decoration, it has to stay where it is but also be unclickable, when I set it to "disabled' state it gets a very ugly filter on it:

enter image description here

How can I make it unclickable without that ugly filter please?

1 Answers1

0

This is an improved version of the previous code.

It will temporarily remove title bar and will restore it if necessary.

Key F1 now controls title bar visibility by acting as a toggle switch.

Now the window can be picked up and moved with Button-1 and Motion at any time.

Escape key or Alt F4 will close window.

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()
Derek
  • 1,916
  • 2
  • 5
  • 15