Search code examples
pythonuser-interfacefiremonkeyproperty-placeholder

How to add placeholder text to Edit in a Python FMX GUI App?


I have made a Form with an Edit component using the DelphiFMX GUI Library for Python and I'm trying to add a placeholder text to the Edit component, but I'm not sure how. I've tried doing self.myEdit.Placeholder = "Enter your name...", but this just gives me an error of AttributeError: Error in setting property Placeholder.

Here's my full code:

from delphifmx import *

class frmMain(Form):
    def __init__(self, owner):
        self.Caption = 'My Form'
        self.Width = 400
        self.Height = 200
        
        self.myEdit = Edit(self)
        self.myEdit.Parent = self
        self.myEdit.Align = "Center"
        self.myEdit.Width = 250

        self.myEdit.Placeholder = "Enter your name..."


def main():
    Application.Initialize()
    Application.Title = "My Application"
    Application.MainForm = frmMain(Application)
    Application.MainForm.Show()
    Application.Run()
    Application.MainForm.Destroy()

main()

My Edit is just empty. I need a placeholder text to be in there.

Is placeholder text available? How do I add placeholder text to the Edit?


Solution

  • In FMX, the Placeholder text is called TextPrompt. So you can simply do:

    self.myEdit.TextPrompt = "Enter your name..."
    

    And that should work as can be seen by the attached screenshot: Python GUI with placeholder edit