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:
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


0