Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8693959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:40:03+00:00 2026-06-13T00:40:03+00:00

I am creating a GUI program that has 25 buttons, each accesses a unique

  • 0

I am creating a GUI program that has 25 buttons, each accesses a unique file in the same folder, I know I can individually program each one to go to each file, but that seems like a lot more code than there needs to be, is there a more efficient way to do this?
here is the code:

box1 = 'C:/Users/Geekman2/Documents/Tests/box1.txt
cupcake = Button(donut,text = "Box #1", command = open(box1))

done this way I would have to create a variable for every file,not very efficient

P.S. if you are confused, I name all of my variables after pastries

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:40:04+00:00Added an answer on June 13, 2026 at 12:40 am

    I would try a code snippet similar to this:

    directory = 'C:/Users/Geekman2/Documents/Tests/'
    ...
    def AddDirTo(filename)
         return directory + filename
    

    Then the code you posted would turn into:

    box1 = AddDirTo('box1.txt') #note: you did close box1's quote on your question
    cupcake = Button(donut,text = "Box #1", command = open(box1))
    

    If every file you have is a text file, as is indicated from the question’s tays, you can even make it:

    directory = 'C:/Users/Geekman2/Documents/Tests/'
    extension = '.txt'
    ...
    def AddDirTo(filename):
         return directory + filename + extension
    ...
    box1 = AddDirTo('box1') #note: you did close box1's quote on your question
    cupcake = Button(donut,text = "Box #1", command = open(box1))
    

    For those of you about to vote this down for the directory and extensionvariables at the top, it makes the code reusable for other directories and extensions, without having to make a new function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a .jar file that has a GUI: jar cmf mainClass patcherFull.jar pack
I am creating a Java program that uses a GUI to display a mortgage
I'm creating a c# winforms project that can be run as a GUI or
I am creating a GUI program that will run 24/7. I couldn't find much
I'm creating a GUI and I would like an app that changes on based
I had a huge file for creating this GUI and I have shortened it
I'm creating a matlab GUI using GUIDE. I can't get the context menus to
I am creating different frames for my GUI(Netbeans drag and drop) and in that
I am creating a popup JFrame that will have a message and yes/no buttons.
I'm looking into creating a GUI program for Windows in C++, I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.