Jump to content

Is it possible to change the text of a GUI button after it is already declared?


Go to solution Solved by l3ill,

Recommended Posts

Posted
 

I have a GUI that contains around 11 buttons that make my job easier, and one of them calculates a percentage. As of now, I have that percentage displaying in a label also in the GUI, but I'd like for it to update the percentage ON THE BUTTON TEXT instead of having to use a label. This may not be possible, because all of the places I've tried it in, in my code, disables the button once it changes the text of the button. Is there any way to do this? I hope this isn't too confusing. I can provide code if needed, however, I didn't because it doesn't seem necessary for this type of issue. Any help is appreciated. Thanks,

 

  • Solution
Posted (edited)

You can change the Button text by using

GUICtrlSetData( $buttonID, "Something")

As mentioned above^^^

Just place it somewhere in the function that should update it.

Replace "Something" with your Percentage variable.

Edited by l3ill
Posted

as the above, with a timer, showing that the button still works fine

#include <GUIConstantsEx.au3>

$hMain=GUICreate("test")
$idButton=GUICtrlCreateButton("Calculate",10,10,100)
GUISetState()

$timer = timerinit()

While 1
    $sTime = round(timerdiff($timer))
    GUICtrlSetData($idButton, $sTime)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idButton
            msgbox(0, '' , $sTime)
    EndSwitch
    sleep(10)
WEnd

  Reveal hidden contents

  • Moderators
Posted

houstonl3,

 

  Quote

Sorry, I kind of feel like a noob now

No need to apologise - we were all at that point once. ;)

As a newcomer to AutoIt, reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at this excellent tutorial - you will find other tutorials in the Wiki (the link is at the top of the page). :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...