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 8727151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:23:08+00:00 2026-06-13T08:23:08+00:00

I’m trying to select an item from a listbox, and when a button is

  • 0

I’m trying to select an item from a listbox, and when a button is pressed, that file’s index position is passed to another function.

Right now I’m just trying to properly select the file but it’s not working. A directory is selected via openfile (yes, bad naming and all)and then it is passed to directoryContents. From here “()” is printed in the command prompt. This should only happen when the button is pressed not immediately as it runs, so that’s part of my problem. Upon selecting an item in the list and pressing the button, nothing happens.

Say I select the first item in the list and press the button, (0) should be printed in the command prompt.

class Actions:

    def openfile(self):
        directory = tkFileDialog.askdirectory(initialdir='.')
        self.directoryContents(directory)


    def filename(self):
        Label (text='Please select a directory').pack(side=TOP,padx=10,pady=10)

    def directoryContents(self, directory):
        scrollbar = Scrollbar() #left scrollbar - display contents in directory
        scrollbar.pack(side = LEFT, fill = Y) 

        scrollbarSorted = Scrollbar() #right scrollbar - display sorted files 
        scrollbarSorted.pack(side = RIGHT, fill = Y, padx = 2)

        fileList = Listbox(yscrollcommand = scrollbar.set) #files displayed in the first scrollbar
        for filename in os.listdir(directory):
            fileList.insert(END, filename)
        fileList.pack(side =LEFT, fill = BOTH)
        scrollbar.config(command = fileList.yview)

        fileList2 = Listbox(yscrollcommand = scrollbarSorted.set) #second scrollbar (button will send selected files to this window)
        fileList2.pack(side =RIGHT, fill = BOTH)
        scrollbarSorted.config(command = fileList2.yview)

        selection = fileList.curselection() #select the file
        b = Button(text="->", command=self.moveFile(selection)) #send the file to moveFile
        b.pack(pady=5, padx =20)

        mainloop()

    def moveFile(self,File):
        print(File)

#b = Button(text="->", command=Actions.moveFile(Actions.selection))
#b.pack(pady=5, padx =20)
  • 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-13T08:23:09+00:00Added an answer on June 13, 2026 at 8:23 am

    One problem that I see pretty quickly is:

    b = Button(text="->", command=self.moveFile(selection))
    

    should be something like:

    b = Button(text="->", command=lambda:self.moveFile(fileList.curselection()))
    

    As it is written, you’re passing the result of self.moveFile as command (which obviously needs to call self.movefile in order to get the result)

    Slipping a lambda in there defers calling the function until the button is actually clicked.

    The mainloop in there also seems a little fishy …

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.