Jump to content
  • Advertisement
Sign in to follow this  

Can this be done with tk button widgets?

This topic is 5477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Not sure if this is more appropriate for the Unix forum, but anyway... I've just started playing around with tcl/tk and I can't find any solutions to what seems like a simple task. I want to create a window consisting solely of a number of buttons. The clicking of these buttons should all run the same program, but each button varies by the single argument passed to the program. Here's what I have so far:
#!/usr/bin/wish -f

foreach arg {servo crow joel} {
    button .$arg 
            -text $arg 
            -command {exec myProgram $arg} 
    pack .$arg             
(ignore any typos or syntax errors - I copied this by hand but the original runs without syntax errors) This creates a three-button window, and clicking on any of the buttons does run the program (execute the command associated with the button), but my problem is that $arg in the command is not resolved until the button is clicked, rather than at the command assignment inside the loop, as I want. So it always evaluates to the last value in the list ("joel" in this case). Does anyone know how to associate the "myProgram <properArg>" command with the buttons, other than hard-coding each one?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!