-
|
Seems like I got the idea wrong, I meant to add the ability to bind tooltips to other widgets, in my application I have a scrolling set of labels, and I want to add tooltips to all of them, but I can't bind the tooltips to the rest of the canvas to have it all scroll and be in the right place when I hover. My code: from tkinter import *
from tkinter import font
from tktooltip import ToolTip
root = Tk()
root.title('Font Families')
fonts=list(font.families())
fonts.sort()
text = "NV"
def populate(frame):
for item in fonts:
label = Label(frame,text=text,font=(item, 40)).pack()
tip = ToolTip(label,msg=item)
def onFrameConfigure(canvas):
canvas.configure(scrollregion=canvas.bbox("all"))
canvas = Canvas(root, borderwidth=0, background="#ffffff")
frame = Frame(canvas, background="#ffffff")
vsb = Scrollbar(root, orient="vertical", command=canvas.yview)
canvas.configure(yscrollcommand=vsb.set)
def _on_mousewheel(event):
canvas.yview_scroll(int(-1*(event.delta/120)), "units")
root.bind_all("<MouseWheel>", _on_mousewheel)
vsb.pack(side="right", fill="y")
canvas.pack(side="left", fill="both", expand=True)
canvas.create_window((4,4), window=frame, anchor="nw")
frame.bind("<Configure>", lambda event, canvas=canvas: onFrameConfigure(canvas))
populate(frame)
root.mainloop()as you can see, I can't bind the Tooltip, it gives the following error: Originally posted by @karimawii in #19 (comment) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
@karimawii there is a bug in your sample code, calling You should probably be doing something like def populate(frame):
for item in fonts:
label = Label(frame,text=text,font=(item, 40))
label.pack()
tip = ToolTip(label,msg=item) |
Beta Was this translation helpful? Give feedback.
@karimawii there is a bug in your sample code, calling
.pack()to yourLabeland then assigning that tolabelwill always be non sincepack()returnsNone.You should probably be doing something like