Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: El mas antiguo en 15 Febrero 2022, 15:57 pm



Título: Emular a un ToolTips con una etiqueta.
Publicado por: El mas antiguo en 15 Febrero 2022, 15:57 pm
Hola gente, ¿Cómo están?, lo que no puedo lograr es hacer que esta parte se mueva a derecha e izquierda según sea el botón que se le pasa el mouse.-

Poner la etiqueta en la función y "x" quede de esta manera:

Código
  1. guia = 20
  2. label_ayuda = ttk.Label(ventana, text="", font = ('vardana', 12))
  3. label_ayuda.place(x=guia, y=200, width=380, height=40)
  4.  

El programa:

Código
  1. from tkinter import *
  2. #import tkinter as tk
  3.  
  4. def ayudaUno(button):
  5.    if button == boton_buscar:
  6.        texto = " Buscar movimientos."
  7.    elif button == boton_editar:
  8.        texto = " Editar movimiento."
  9.    elif button == boton_cerrar:
  10.        texto = " Cerrar aplicación."
  11.  
  12.    button.bind("<Enter>", func=lambda e: label_ayuda.config( text=texto))
  13.    button.bind("<Leave>", func=lambda e: label_ayuda.config( text=''))  
  14.  
  15. def centrarVentana(ventana):
  16.    ancho_ventana = 500
  17.    alto_ventana = 260
  18.  
  19.    x_ventana = ventana.winfo_screenwidth() // 2 - ancho_ventana // 2
  20.    y_ventana = ventana.winfo_screenheight() // 2 - alto_ventana // 2
  21.  
  22.    posicion = str(ancho_ventana) + "x" + str(alto_ventana) + "+" + str(x_ventana) + "+" + str(y_ventana)
  23.    ventana.geometry(posicion)
  24.  
  25.    ventana.resizable(0,0)
  26.  
  27.  
  28. ventana = Tk()
  29. ventana.title('Practica')
  30. centrarVentana(ventana)
  31.  
  32. label_ayuda = ttk.Label(ventana, text="", font = ('vardana', 12))
  33. label_ayuda.place(x=20, y=200, width=380, height=40)
  34.  
  35. boton_buscar = Button(ventana, text ="Buscar", relief=RAISED, background="light grey")
  36. boton_buscar.place(x=100, y=160, width=80, height=40)
  37.  
  38. boton_editar = Button(ventana, text ="Editar", relief=RAISED, background="light grey")
  39. boton_editar.place(x=200, y=160, width=80, height=40)
  40.  
  41. boton_cerrar = Button(ventana, text ="Cerrar", relief=RAISED, background="light grey", command = ventana.destroy )
  42. boton_cerrar.place(x=300, y=160, width=80, height=40)
  43.  
  44. ayudaUno(boton_buscar)
  45. ayudaUno(boton_editar)
  46. ayudaUno(boton_cerrar)
  47.  
  48. ventana.mainloop()
  49.  

Slds. Daniel ☕☕☕