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

  • Home
  • SEARCH
  • 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 6736083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:05:18+00:00 2026-05-26T11:05:18+00:00

So, what I am trying to do is open a file when pressing a

  • 0

So, what I am trying to do is open a file when pressing a button and displaying the contents in a listbox. This is what I have so far, but I am not getting the listbox to display, let alone get the info to be in the listbox:

#!/usr/bin/perl -w

import time
from Tkinter import *
import tkFileDialog

def listbox(listbox):

    def open_file():
            file = tkFileDialog.askopenfilename()
            openFile = open(file)
            for line in openFile:
                 listbox.insert(END, line)

    open_file()


class App:

    def __init__(self, parent):

        frame = Frame(parent.title("Buttons"))
        frame.pack()
        root.pack_propagate(0)

        self.exit = Button(frame, text="QUIT", fg="red", command=frame.quit)
        self.exit.pack(side=LEFT)

        self.open = Button(frame, text="Open...", command=self.call_listbox)
        self.open.pack(side=LEFT)

        frame.listbox = Frame()
        scrollme = Scrollbar(frame.listbox)
        self.listbox = Listbox(frame.listbox, yscrollcommand = scrollme.set)
        scrollme.config(command = self.listbox.yview)
        scrollme.pack(side = RIGHT, fill = Y)
        self.listbox.pack()
        self.listbox.insert(END, "Code:")

    def call_listbox(self):
        listbox(self.listbox)

root = Tk()
app = App(root)
root.mainloop()

any suggestions? thanks

  • 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-05-26T11:05:19+00:00Added an answer on May 26, 2026 at 11:05 am

    You are forgetting to pack the frame that contains the listbox.

    FWIW, your overloading of the name “listbox” makes your code very confusing – you have def listbox(listbox), self.listbox and frame.listbox. And you also have call_listbox and the Listbox class to add to the confusion.

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

Sidebar

Related Questions

I'm trying open a txt file and read it, but I'm getting a type
I am trying to open .pdf file in IE7 and firefox, but its not
I'm trying to open a file with Python, but I'm unsure how to find
I'm trying to open a file with fopen, but I don't want a static
I am just trying to open this file and use the getline function to
When trying to open a file using this command: $fd = fopen('majestic_files/majestic_record.txt','w'); I get
I'm trying to open a file, and read from it.. but I'm having some
I'm trying to open a file using fopen, and I am getting the error:
I'm trying to open an .html file as one big long string. This is
I am trying to open a file from a server I currently have Dim

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.