gnikit / tkinter-tooltip

A ToolTip widget for tkinter
https://gnikit.github.io/tkinter-tooltip
MIT License
38 stars 3 forks source link

tooltip does not wrap properly if you change attributes. #97

Closed atannen closed 4 months ago

atannen commented 4 months ago

The following code makes a button and attaches a tooltip.

1) without the bg= line, it wraps the tooltip balloon text properly. 2) with the bg= and fg= line, (without aspect=) it wraps wrong. (Commu newline nity.) 3) with bg= fg= and aspect=1000, it wraps properly again.

It looks like the apsect value is getting trashed or ignored when bg and fg are set. I don't know whether this is intended behavior, but I found it confusing.

import tkinter as tk
import tkinter.ttk as ttk
from tktooltip import ToolTip

app = tk.Tk()
b = ttk.Button(app, text="Button")
b.pack()
tip = ToolTip(b, msg="Community",

# bg="lemonchiffon", fg="blue", aspect=1000,
bg="lemonchiffon", fg="blue",

)
app.mainloop()

This on Ubuntu 22.04 with Python 3.10.12 and tktooltip from pip: Name: tkinter-tooltip Version: 3.0.0

gnikit commented 4 months ago

Tooltip has default kwargs, for now it is just the aspect, see. If you override the defaults you are responsible for providing aspect, which I think is somewhat reasonable.

How would you suggest allowing for overridable defaults through kwargs?

dmd commented 4 months ago

You have:

self.message_kwargs: dict = message_kwargs or self.DEFAULT_MESSAGE_KWARGS

Instead I would expect to see:

self.message_kwargs = self.DEFAULT_MESSAGE_KWARGS.copy()
self.message_kwargs.update(message_kwargs)
gnikit commented 4 months ago

That's a substantially better solution thanks @dmd, will fix now

gnikit commented 4 months ago

Just issued v3.1.0, you should be able to grab the changes there.