houstonl3

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

6 posts in this topic

 

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,

 

Share this post


Link to post
Share on other sites



#3 ·  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

Share this post


Link to post
Share on other sites

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

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Thanks guys. Sorry, I kind of feel like a noob now. I'm a little new to this. I really appreciate it though.

Share this post


Link to post
Share on other sites

houstonl3,

 

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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