Python - Como puedo detectar evento del click en la barra de herraminetas con python

 
Vista:
sin imagen de perfil
Val: 2
Ha disminuido su posición en 18 puestos en Python (en relación al último mes)
Gráfica de Python

Como puedo detectar evento del click en la barra de herraminetas con python

Publicado por Luis (1 intervención) el 11/04/2020 20:39:18
Hola soy nuevo en este foro, estoy programado una ventana sin bordes en tkinter, el problema es que al quitar el borde se elimina por completo el gestor de ventana, logre solucionar esto con ctypes añadiendo en icono a la barra de tarea, el problema esta
cuando quiero minimizar dando click sobre el icono, la ventana sigue en frente, y no desaparece. Me gustaría poder detectar los eventos del sobre este icono, para simular que se minimiza la ventana con attributes ('-alpha', 0.0)
intente captar dichos eventos con <Unmap> y <Map> de tkinter para detectar dicho evento. pero simplemente no funciona.

Este es el código:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import tkinter as tk
from ctypes import windll
from PIL import Image, ImageTk
 
class TitleBar:
 
    def __init__ (self):
 
        self.icon = Image.open ('icono.ico')
        self.icon = self.icon.resize ((25,25))
 
        self.icon = ImageTk.PhotoImage (self.icon)
 
        self.Bar = tk.Frame (self, bd = 0, bg = '#000000')
        self.Bar.pack(side = tk.TOP, fill = tk.X)
 
        self.buttonquit = tk.Button (self.Bar, bd = 0, bg = '#AF0000', fg = '#E6E6E6', text = ' X ', command = lambda:self.quit())
        self.buttonquit.pack(side = tk.RIGHT, padx = 4, pady = 4)
 
        self.__ico = tk.Label (self.Bar, bg = '#000000', image = self.icon)
        self.__ico.pack (side = tk.LEFT)
 
        self.__title = tk.Label (self.Bar, bg = '#000000', fg = '#E6E6E6', text = self.Name)
        self.__title.pack (side = tk.LEFT, padx = 5)
 
        self.bind ("<Button-1>", self.__OnClick)
        self.bind ("<ButtonRelease-1>",self.__OffClick)
        self.bind ("<B1-Motion>", self.__Move)
 
    def __OnClick (self, event):
 
        self.X, self.Y = event.x, event.y
 
    def __OffClick (self, event):
 
        self.X, self.Y = None, None
 
    def __Move (self, event):
 
        P1, P2 = event.x - self.X, event.y - self.Y
 
        self.geometry (f'+{P1 + self.winfo_x()}+{P2 + self.winfo_y()}')
 
 
class Window (tk.Tk, TitleBar):
 
    def __init__ (self):
 
        self.GWL_EXSTYLE=-20
        self.WS_EX_TOOLWINDOW=0x00000080
 
        self.width, self.height = 400, 500
 
        super (Window, self).__init__()
        self.overrideredirect(True)
        self.after (10, self.RemoveBorde)
 
        self.Center()
 
        self.Name = 'windows'
        self.wm_title (self.Name )
        self.iconbitmap('icono.ico')
 
        windll.shell32.SetCurrentProcessExplicitAppUserModelID(self.Name)
        TitleBar.__init__ (self)
 
    def RemoveBorde (self):
 
        self.h = windll.user32.GetParent(self.winfo_id())
        self.style = windll.user32.GetWindowLongW(self.h, self.GWL_EXSTYLE)
        self.style = self.style & ~self.WS_EX_TOOLWINDOW
        windll.user32.SetWindowLongW(self.h, self.GWL_EXSTYLE, self.style)
 
        self.wm_withdraw()
        self.after(10, lambda: self.wm_deiconify())
 
    def Center (self):
 
        x, y = (self.winfo_screenwidth()//2 - self.width//2 ), (self.winfo_screenheight()//2 - self.height//2)
 
        self.geometry (f'{self.width}x{self.height}+{x}+{y}')
 
if __name__ == '__main__':
 
   App =  Window()
   App.mainloop()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 2.808
Oro
Ha mantenido su posición en Python (en relación al último mes)
Gráfica de Python

Como puedo detectar evento del click en la barra de herraminetas con python

Publicado por tincopasan (1082 intervenciones) el 12/04/2020 10:37:42
hola:
no sé si entendí bien tu pregunta, pero agregue dos huevadas y fijate si es más o menos eso lo que buscas.
1)
1
self.__ico = tk.Label (self.Bar, bg = '#000000', image = self.icon,name="icono")
2)
1
2
3
4
5
6
def __OnClick (self, event):
        self.X, self.Y = event.x, event.y
        posx,posy =self.winfo_pointerxy()
        widget = str(self.winfo_containing(posx,posy))
        if widget  ==".!frame.icono":
            print("minimizar")  #acá iria lo que querés hacer, solo puse el print para que se vea que haces click sobre el icono.

Sino es, perdón pero me cuesta entender algunos planteos.

Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar