add new class for tooltip
This commit is contained in:
parent
8896f59efd
commit
2a3bf2bbcb
Binary file not shown.
@ -389,3 +389,41 @@ def if_tip(path):
|
|||||||
else:
|
else:
|
||||||
tip = True
|
tip = True
|
||||||
return tip
|
return tip
|
||||||
|
|
||||||
|
class Tooltip:
|
||||||
|
"""
|
||||||
|
class for Tooltip
|
||||||
|
|
||||||
|
imoprt Tooltip
|
||||||
|
|
||||||
|
example: Tooltip(label, "Show tooltip on label")
|
||||||
|
examble: Tooltip(button, "Show tooltip on button")
|
||||||
|
info: label and button is parrent.
|
||||||
|
"""
|
||||||
|
def __init__(self, widget, text):
|
||||||
|
self.widget = widget
|
||||||
|
self.text = text
|
||||||
|
self.tooltip_window = None
|
||||||
|
self.widget.bind("<Enter>", self.show_tooltip)
|
||||||
|
self.widget.bind("<Leave>", self.hide_tooltip)
|
||||||
|
|
||||||
|
def show_tooltip(self, event=None):
|
||||||
|
if self.tooltip_window or not self.text:
|
||||||
|
return
|
||||||
|
|
||||||
|
x, y, _, _ = self.widget.bbox("insert")
|
||||||
|
x += self.widget.winfo_rootx() + 25
|
||||||
|
y += self.widget.winfo_rooty() + 20
|
||||||
|
self.tooltip_window = tw = tk.Toplevel(self.widget)
|
||||||
|
tw.wm_overrideredirect(True)
|
||||||
|
tw.wm_geometry(f"+{x}+{y}")
|
||||||
|
|
||||||
|
label = tk.Label(tw, text=self.text, relief="solid", borderwidth=1, padx=5, pady=5)
|
||||||
|
label.grid()
|
||||||
|
|
||||||
|
def hide_tooltip(self, event=None):
|
||||||
|
if self.tooltip_window:
|
||||||
|
self.tooltip_window.destroy()
|
||||||
|
self.tooltip_window = None
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@ import tkinter as tk
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from subprocess import check_call
|
from subprocess import check_call
|
||||||
from tkinter import filedialog, ttk, TclError
|
from tkinter import filedialog, ttk, TclError
|
||||||
from cls_mth_fc import Tunnel, Create, msg_window, if_tip, GiteaUpdate, uos
|
from cls_mth_fc import Tooltip, Tunnel, Create, msg_window, if_tip, GiteaUpdate, uos
|
||||||
|
|
||||||
uos()
|
uos()
|
||||||
Create.dir_and_files()
|
Create.dir_and_files()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user