user14452947
user14452947

Reputation:

Desktop Goose like program

i have been trying to create a python program similar to desktop goose in the aspect of a widget moving freely around the screen.

First i tried to create a window with tkinter and make a transparent window with a PNG picture of a character and then moving the window with win32gui or any other library that would allow me to do this. But first, the tkinter transparent window thing doesn't work because the widgets inherit the transparency, so there is no way i can display the PNG. Then i had trouble finding any win32gui function that would allow me to move the windows, i just found stuff that would let me resize them.

Is there any way i can do any of these two tasks?

Upvotes: 0

Views: 3561

Answers (1)

acw1668
acw1668

Reputation: 47219

You can create a transparent window using a transparent PNG image as below:

import tkinter as tk

# select a color as the transparent color
TRNAS_COLOR = '#abcdef'

root = tk.Tk()
root.overrideredirect(1)
root.attributes('-transparentcolor', TRNAS_COLOR)

image = tk.PhotoImage(file='/path/to/image.png')
tk.Label(root, image=image, bg=TRNAS_COLOR).pack()

# support dragging window

def start_drag(event):
    global dx, dy
    dx, dy = event.x, event.y

def drag_window(event):
    root.geometry(f'+{event.x_root-dx}+{event.y_root-dy}')

root.bind('<Button-1>', start_drag)
root.bind('<B1-Motion>', drag_window)

root.mainloop()

Then you can use root.geometry(...) to move the root window.

Upvotes: 1

Related Questions