Make a message appears on button click

hello , i am new to pyrevit and i am testing a small python script with rpw.
how can i make a message appears 'hello world ’ when i click on the button named generate text?
any help would be appreciated.

and here is my UI+script

the script:

# -*- coding: utf-8 -*-

import sys
import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
clr.AddReference('Microsoft.Office.Interop.Excel')
from Autodesk.Revit.UI import *
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import *
from Autodesk.Revit.DB import Transaction
from rpw.ui.forms import Console, FlexForm, Label, TextBox, Button, select_file, Alert
from Microsoft.Office.Interop import Excel
from pyrevit import forms

doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument

t = Transaction(doc, 'Create Sheet')

components = [
    Label('Sheet Name'),
    TextBox('textbox1'),
    Label('Sheet Number'),
    TextBox('textbox2'),
    Button('select excel !'),
    Button('Generate text!')
]

form = FlexForm('Create sheet', components)
form.show()


def generate_button_clicked(sender, args):
    Alert("Hello there!", title="Greetings")


form.add_button('Generate text!', on_click=generate_button_clicked)

Hi @FethiSekinKız and welcome,

It does not look like a small python script to me but a rather big one if you are new to it :slight_smile:

I striped down your script a bit.
It works like so:

# -*- coding: utf-8 -*-

from rpw.ui.forms import FlexForm, Label, TextBox, Button, Alert
from pyrevit import revit

doc = revit.doc

def generate_button_clicked(sender, args):
    """
    This function is called when the 'on click do this' pushbutton is clicked. It displays an alert with the message 'Hello there!' and the title 'Greetings'.
    """
    Alert("Hello there!", title="Greetings")

components = [
    Label('Sheet Name'),
    TextBox('textbox1'),
    Label('Sheet Number'),
    TextBox('textbox2'),
    Button('On click do this', on_click=generate_button_clicked),
    Button('Generate text!')
]

form = FlexForm('Create sheet', components)
form.show()
1 Like

oh thank you a lot @Jean-Marc your script worked perfectly . its like a small project i am doing by myself to practice python. i really adore your help