Closed joshjaysalazar closed 2 months ago
I would like to take a crack at this, could you share the tooltip class?
I would like to take a crack at this, could you share the tooltip class?
Yup, sure thing. Here's the code (be sure to keep the attribution the same at the top, as this is code from another open source repository):
""" tk_ToolTip_class101.py
gives a Tkinter widget a tooltip as the mouse is above the widget
tested with Python27 and Python34 by vegaseat 09sep2014
www.daniweb.com/programming/software-development/code/484591/a-tooltip-class-for-tkinter
Modified to include a delay time by Victor Zaccardo, 25mar16
"""
try:
# for Python2
import Tkinter as tk
except ImportError:
# for Python3
import tkinter as tk
class CreateToolTip(object):
"""
create a tooltip for a given widget
"""
def __init__(self, widget, text='widget info'):
self.waittime = 500 #miliseconds
self.wraplength = 180 #pixels
self.widget = widget
self.text = text
self.widget.bind("<Enter>", self.enter)
self.widget.bind("<Leave>", self.leave)
self.widget.bind("<ButtonPress>", self.leave)
self.id = None
self.tw = None
def enter(self, event=None):
self.schedule()
def leave(self, event=None):
self.unschedule()
self.hidetip()
def schedule(self):
self.unschedule()
self.id = self.widget.after(self.waittime, self.showtip)
def unschedule(self):
id = self.id
self.id = None
if id:
self.widget.after_cancel(id)
def showtip(self, event=None):
x = y = 0
x, y, cx, cy = self.widget.bbox("insert")
x += self.widget.winfo_rootx() + 25
y += self.widget.winfo_rooty() + 20
# creates a toplevel window
self.tw = tk.Toplevel(self.widget)
# Leaves only the label and removes the app window
self.tw.wm_overrideredirect(True)
self.tw.wm_geometry("+%d+%d" % (x, y))
label = tk.Label(self.tw, text=self.text, justify='left',
background="#ffffff", relief='solid', borderwidth=1,
wraplength = self.wraplength)
label.pack(ipadx=1)
def hidetip(self):
tw = self.tw
self.tw= None
if tw:
tw.destroy()
I'd put this tooltip class in its own file (say core/tooltip.py, for example) and import it wherever you need to create tooltips. Let me know if you need me to clarify the content of any tooltips, or anything else.
NOTE: It's worth mentioning that there's a library called Tix that can do tooltips, but it is not maintained anymore, so I'd like to avoid using it.
Oh, and if you need a usage example, I used them here: https://github.com/joshjaysalazar/AutoRGB/blob/master/autorgb/MainWindow.py
You do not have to follow the style of that code--that is some very old code from me at this point. But you can at least see how it gets implemented if you need to.
@praneetheus Just wanted to see if you needed any help with this. No pressure, there's no timeline. Just wanted to check in.
@joshjaysalazar I am not a python dev, I took a crack at it, but ran into env issues (PyInstaller) and then windows defender being a pain by removing some build files as they are marked as a trojan. I need to look up setting virtual environments perhaps
@praneetheus A virtual env will definitely help. Pyinstaller does unfortunately get flagged by Windows now. It's definitely a problem that needs solving. I told Windows to ignore it, myself.
@joshjaysalazar I made some progress with this, is there any particular text you want for the labels?
I didn't have specific phrasing in mind, just clean, succinct, and grammatically correct. 😂 If you're not sure what an option does, ping me, and I can give you some specific text. We can also correct any errors in the review process once you're ready to do a pull request.
Hey, I created a PR. I wasn't sure what to add for 'Immediate wave around', just have a placeholder there for now. Let me know what you text you want me to add here.
Alright, I'll take a look at it when I can, and I'll note what to put there in a revision request. Thanks!
Is your feature request related to a problem? Please describe. The GUI is lacking more detailed information in the name of keeping the interface simple. Without an instruction manual, this means there are options which may not be clear to the user.
Describe the solution you'd like Add hover tooltips to every option, so the user can get more information.
Describe alternatives you've considered Writing more detailed instructions in the README is also a reasonable option. Really, both should probably be implemented.
Additional context To whomever takes on this issue, I have a tooltip class from a previous program I can share, which will make this extremely easy to implement.