Search code examples
pythonuser-interfacefiremonkey

What is the absolute simplest way to make a Python FMX GUI App?


I've got the following Python code to make the FMX GUI Form, but I'm trying to make the code shorter if possible. What is the least amount of code that is required to make only a Form and show it. Here's my current code:

from delphifmx import *

class frmMain(Form):
    def __init__(self, owner):
        self.Width = 300
        self.Height = 150


Application.Initialize()
Application.MainForm = frmMain(Application)
Application.MainForm.Show()
Application.Run()
Application.MainForm.Destroy()

Python GUI Empty Form

Is there a way to decrease the code? Maybe a shorter way to write the same code?


Solution

  • You don't necessarily need to create a class of Form: class frmMain(Form). You could just initialize and create the Form the same way you would create a component:

    from delphifmx import *
    
    Application.Initialize()
    frmMain = Form(Application)
    Application.MainForm = frmMain
    frmMain.Show()
    Application.Run()
    frmMain.Destroy()
    

    And that'll show:

    Python GUI Empty Form

    Although it is most likely better practice to do it by creating a class of the Form like you have done in the question if you're building a big application.

    Also have a look at this simplest.py sample code.