Last change
on this file since 1279 was
1198,
checked in by Maciej Komosinski, 22 months ago
|
Added simple Python GUI for Framsticks library/server
|
File size:
1.1 KB
|
Rev | Line | |
---|
[1198] | 1 | import tkinter as tk
|
---|
| 2 |
|
---|
| 3 | class ToolTip(object):
|
---|
| 4 |
|
---|
| 5 | def __init__(self, widget):
|
---|
| 6 | self.widget = widget
|
---|
| 7 | self.tipwindow = None
|
---|
| 8 | self.id = None
|
---|
| 9 | self.x = self.y = 0
|
---|
| 10 |
|
---|
| 11 | def showtip(self, text, event):
|
---|
| 12 | "Display text in a tooltip window"
|
---|
| 13 | self.text = text
|
---|
| 14 | if self.tipwindow or not self.text:
|
---|
| 15 | return
|
---|
| 16 |
|
---|
| 17 | x = event.x_root + 5
|
---|
| 18 | y = event.y_root + 5
|
---|
| 19 | self.tipwindow = tw = tk.Toplevel(self.widget)
|
---|
| 20 | tw.wm_overrideredirect(1)
|
---|
| 21 | tw.wm_geometry("+%d+%d" % (x, y))
|
---|
| 22 | label = tk.Label(tw, text=self.text, justify=tk.LEFT, background="#ffffe0", relief=tk.SOLID, borderwidth=1, font=("tahoma", "8", "normal"))
|
---|
| 23 | label.pack(ipadx=1)
|
---|
| 24 |
|
---|
| 25 | def hidetip(self):
|
---|
| 26 | tw = self.tipwindow
|
---|
| 27 | self.tipwindow = None
|
---|
| 28 | if tw:
|
---|
| 29 | tw.destroy()
|
---|
| 30 |
|
---|
| 31 | def CreateToolTip(widget, text):
|
---|
| 32 | toolTip = ToolTip(widget)
|
---|
| 33 | def enter(event):
|
---|
| 34 | toolTip.showtip(text, event)
|
---|
| 35 | def leave(event):
|
---|
| 36 | toolTip.hidetip()
|
---|
| 37 | widget.bind('<Enter>', enter)
|
---|
| 38 | widget.bind('<Leave>', leave) |
---|
Note: See
TracBrowser
for help on using the repository browser.