I have created a window Form
with a Button
on it with the DelphiFMX GUI library for Python. I want to be able to add a hover tooltip to the button which explains what it does. Here's an example of a button tooltip on a Form, when I hover on it with my mouse, then it shows "I am a button":
Here's the code I currently have to create my Form with Button:
from delphifmx import *
class frmMain(Form):
def __init__(self, owner):
self.Caption = 'My Form'
self.Width = 1000
self.Height = 500
self.Position = "ScreenCenter"
self.myButton = Button(self)
self.myButton.Parent = self
self.myButton.Text = "Hello World!"
self.myButton.Align = "Client"
self.myButton.Margins.Top = 20
self.myButton.Margins.Right = 20
self.myButton.Margins.Bottom = 20
self.myButton.Margins.Left = 20
self.myButton.StyledSettings = ""
self.myButton.TextSettings.Font.Size = 50
self.myButton.onClick = self.Button_OnClick
def Button_OnClick(self, sender):
print("Hello World!")
def main():
Application.Initialize()
Application.Title = "My Application"
Application.MainForm = frmMain(Application)
Application.MainForm.Show()
Application.Run()
Application.MainForm.Destroy()
main()
I tried doing self.myButton.toolTip = "Click me!"
, but this doesn't work.
How do tooltips work in the DelphiFMX library?
Tooltips
in DelphiFMX are called Hints
. Here's how you would add a Hint to your button:
self.myButton.Hint = "Click me!"
self.myButton.ShowHint = True
Here's a screenshot of that exact code that shows the "Click me!" tooltip/hint when I hovered on it:
You simply use the Hint
property to add your string and then set ShowHint
to True.
You can also do multi-line hints by adding chr(13) + chr(10)
to your Hint string:
self.myButton.Hint = "Click me!" + chr(13) + chr(10) + "I'm a button!"
self.myButton.ShowHint = True