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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:25:32+00:00 2026-06-04T08:25:32+00:00

i am having trouble loading one of my text files into my GUI. I

  • 0

i am having trouble loading one of my text files into my GUI. I have a load function(on the menubar), and have created a listbox.

The code for the loading the menu and the listbox:

class View(Listbox):
    def __init__(self, master):
        Listbox.__init__(self, master)      #makes view class listbox


class Controller(object):
    def __init__(self, master):
        """ Main interface:
        master - the top level window

        """
        self._master = master
        menubar = Menu(self._master)

        frame1 = Frame(self._master)
        frame1.pack(side=TOP, fill=BOTH, padx=5,expand=True)

        self._Listbox=View(frame1)
        self._Listbox.pack(side = TOP,fill=BOTH, expand = True,pady=20)

        menubar = Menu(self._master)
        filemenu = Menu(menubar, tearoff=0)
        filemenu.add_command(label="Open rooms file", command = self.file_open)


    def file_open(self):
        filename = tkFileDialog.askopenfilename() 

The load file works, but where is the text document being currently loaded? How can i display it on my listbox?

  • 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-04T08:25:33+00:00Added an answer on June 4, 2026 at 8:25 am

    This works:

    from Tkinter import *
    import tkFileDialog
    
    class View(Listbox):
        def __init__(self, master):
            Listbox.__init__(self, master)      #makes view class listbox
    
    
    class Controller(object):
        def __init__(self, master):
            """ Main interface:
            master - the top level window
            """
            self._master = master
    
            frame1 = Frame(self._master)
            frame1.pack(side=TOP, fill=BOTH, padx=5,expand=True)
    
            self._Listbox=View(frame1)
            self._Listbox.pack(side = TOP,fill=BOTH, expand = True,pady=20)
    
            menubar = Menu(self._master)
            filemenu = Menu(menubar, tearoff=0)
            filemenu.add_command(label="Open", command = self.file_open)
            menubar.add_cascade(label='File',menu=filemenu)
            self._master.config(menu=menubar)
    
        def file_open(self):
            filename = tkFileDialog.askopenfilename()
    
            #insert each line in the file into the listbox
            with open(filename,'r') as f:
                for line in f:
                    self._Listbox.insert(END,line)
    
    
    
    if __name__ == "__main__":
        root=Tk()
        c=Controller(root)
        root.mainloop()
    

    This is only slightly different than your code… First, I removed the first menubar = Menu(self._master) since it didn’t really do anything. Second, I added a “cascade” menubar.add_cascade(label='File',menu=filemenu), third, I actually attached the menu to the root Tk window: self._master.config(menu=menubar)

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

Sidebar

Related Questions

I'm having a bit of trouble loading pages into an already-existing colorbox. I have
I'm having trouble loading image data into a draggable window using EXT JS. The
I am having trouble loading .swf files to my flash app off my cloudstorage
Having trouble with each function... Will try to explain by example... In my code,
I am having some trouble loading images from a file into an array. I
I'm having trouble loading custom HTML into my UIWebView without breaking its goBack method.
I am having trouble loading multiple javascripts in HTML page. Here is the code
I'm having some trouble understanding how codeigniters loading works. Well first you have the
i am having trouble with image loading and triggering with safari/mobile safari. i have
I'm having trouble loading CSS for my Django template. I have the following settings:

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.