Making a picture change RANDOMLY IN A GUI

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ryanjordan
Posts: 15
Joined: 29 May 2017, 20:31

Making a picture change RANDOMLY IN A GUI

20 Sep 2017, 16:14

The code below, changes a picture RANDOMLY every 5 seconds.
The problem is that every time this happens A NEW GUI is generated with a new picture.

Please help me to understand how the GUI will stay the same and NOT re-generate and INSTEAD just the
picture changes.

Help is greatly appreciated. Thank you in advance!!






^8::
#Persistent
loop, C:\Users\hp\Pictures\positive stuff\*.JPG,0,1
tot++

redo:
Random, select, 1, %tot%

Loop, C:\Users\hp\Pictures\positive stuff\*.JPG
IfEqual, A_Index, %select%, Setenv, file, %A_LoopFileFullPath%

Gui, russ:destroy
Gui, russ: +LastFound +Owner
Gui, russ:Color, Black
Gui, russ:Add, Picture, x0 y0 w1300 h770 vPic, %file%
Gui, russ:Show, x150 y910 w1300 h770, gui name

sleep 5000
goto redo

return

return
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Making a picture change RANDOMLY IN A GUI

20 Sep 2017, 16:33

Use GuiControl to update an existing control.

What I would do is first create your GUI. Then enter in a loop to use just the GuiControl command and the Sleep 5000. Or, slightly preferably, SetTimer on a 5 second intersection.
ryanjordan
Posts: 15
Joined: 29 May 2017, 20:31

Re: Making a picture change RANDOMLY IN A GUI

20 Sep 2017, 17:07

Hello Exaskryz, I have being playing with this for awhile. Just getting various errors.

Is it possible that you could show me a SMALL EXAMPLE so I can compare my mishaps with your small sample.

I do understand if your are tooo busy.

Thank you for the post.

Cheers
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Making a picture change RANDOMLY IN A GUI

20 Sep 2017, 19:41

One thing I forgot in the loop is you'd want to repeat your Random command too.

Code: Select all

Gui, Russ:Add, Picture, vPic, Tulips.jpg
Gui, Russ:Show
Sleep 2000
GuiControl, Russ:, Pic, Roses.jpg


You'll notice that I put a "blank" command in the first parameter of GuiControl. I still put the name prefix and the colon to specify which GUI I was working on (unnecessary if Russ is the default GUI, however, I have a habit of including my names always). Also notice that I used the name of the variable in the second parameter of GuiControl.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Making a picture change RANDOMLY IN A GUI

20 Sep 2017, 19:50

Btw the #persistent directive is unecessary in your script:
Any script that uses the GUI command anywhere is automatically persistent (even if the GUI command is never actually executed).
source: GUI
Once a script has at least one hotkey, it becomes persistent, meaning that ExitApp rather than Exit should be used to terminate it.
source: Hotkeys
my scripts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 358 guests