There are several ways to solve this (including deriving classes), but the
simplest for you right now is probably to have `initialize-progress-bar'
return the gui widgets (in particular `gauge' and `msg'), assign the values
to `the-gauge' and `the-msg' (say) from the return values of
`(initialize-progress-bar)` call, and then pass these values to
`update-progress-bar' so that `gauge' and `msg' have the correct values
there.

Does that make sense?

On Tue, Jul 9, 2019 at 7:23 AM Travis Hinkelman <travis.hinkel...@gmail.com>
wrote:

> Hi All,
>
> I was playing around with creating a progress bar. The basic idea was
> straightforward.
>
> #lang racket/gui
>
> (define frame (new frame%
>                    [label "Progress Bar"]
>                    [width 300]))
>
> (define hpane (new horizontal-pane%
>                    [parent frame]))
>
> (define gauge (new gauge%
>                    [label ""]
>                    [parent hpane]
>                    [range 100]))
>
> (define msg (new message%
>                  [parent hpane]
>                  [auto-resize #t]
>                  [label "0%"]))
>
> (send frame show #t)
>
> (for ([i (in-range 1 101)])
>   (sleep 0.05)
>   (send gauge set-value i)
>   (send msg set-label (string-append (~a i) "%")))
>
>
> When I tried to take the next step of wrapping this up into a couple of
> functions, I was completely lost. I don't know how to initialize a frame
> with child elements by calling a function because all of the elements of
> the frame only exist in the function and not at the top-level (probably
> butchering the jargon here; hopefully it makes sense). I wasn't really sure
> where to look to learn more about doing such a thing. Here is some
> pseudocode to try to further illustrate my confusion.
>
> (define (initialize-progress-bar)
>   ;; insert code that creates progress bar
>   ;; i.e., from defining frame to sending frame in code above)
>
> (define (update-progress-bar new-value)
>   (send gauge set-value new-value)
>   (send msg set-label (string-append (~a new-value) "%")))
>
> (initialize-progress-bar)
> (for ([i (in-range 1 101)])
>   (sleep 0.05)
>   (update-progress-bar i))
>
> Thanks,
>
> Travis
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/61a3ea75-d285-45d1-90d4-de569c441c8d%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/61a3ea75-d285-45d1-90d4-de569c441c8d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABNTSaEaaAaQSneGi2yOR4dv_0hOz_WYbaQ4v19q4%2BuXY_E%3Dhw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to