[ Foro de Python ]

Como puedo capturar el evento del icono de la barra de herramienta con ctypes

11-Apr-2020 19:23
Invitado (Darz0101)
0 Respuestas

Diseño una ventana sin borde en tkinter, he usado ctypes para añadir el icono  a la barra de herramienta, pero mi problema esta en cuando quiero minimizar la ventana desde el icono de la barra, si presiono click  sobre el, la ventana sigue al frente y no se oculta, me gustaría saber como puedo capturar esos eventos,  para ocultar la ventana y des ocultar  y así simular que esta minimizada! intente con los eventos de tkinter como Unmap y map, pero simplemente no detecta dichos evento.

Este es el codigo:
import tkinter as tk
from ctypes import windll

class Window (tk.Tk):

   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)


       tk.Button (self, text = 'X', command = lambda:self.quit()).place (x = 10, y = 10)

   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()




(No se puede continuar esta discusión porque tiene más de dos meses de antigüedad. Si tienes dudas parecidas, abre un nuevo hilo.)