huntaz556 0 Newbie Poster

i have things in a text file an index of movies that one owns and can add more but when i want to add a new one but when i have it print the line of a text file it just does this.
i
k
o
g
n
how can i do that and have it display all the contents of my text file instead of just one line

here is my code right now

import easygui
import sys
import os
from easygui import *
msgbox(msg='This program is to keep track of all the movies you own',title='Movie Catalog',ok_button='OK',image=None,root=None)
wouldyou = choicebox(msg='Would you like to enter a movie or view the movies you already own?',title='',choices=('Enter a movie', 'View my movies'))
if wouldyou == "Enter a movie":
    msg='Please enter the name of the movie'
    title='Movie Catalog'
    fieldNames=("Name of movie", "Genre", "Movie description")
    fieldValues = []
    fieldValues = multenterbox(msg, title, fieldNames)
    if fieldValues == None:
        sys.exit(0);
        
    fp_out = open("movies.txt", "a")

#enter_another = True
#while enter_another:
    myString = "**".join(fieldValues)
    fp_out.write("%s\n" %(myString))
    fp_out.close() 

elif wouldyou == "View my movies":
    all_movies = open("movies.txt", "r").readlines()
    for ctr, rec in enumerate(all_movies):
        name,genre,desc = rec.strip().split("**")
    #print "%5s %10s        %s" % (name, genre, desc)
	choicebox(msg='', title=' ', choices=("%s" % (name)))


    


raw_input("press any key to exit")

Dani AI

Generated

— the output you described (one character per line) happens when EasyGUI gets a plain string for choices. EasyGUI treats the choices argument as an iterable and will iterate a string character-by-character, so passing a single string makes each character appear as its own choice. The fix is to build and pass a list (or tuple) of movie strings.

A simple, robust pattern to load titles and call choicebox:

from easygui import choicebox

def load_titles(filename):
    titles = []
    with open(filename, 'r') as fh:
        for raw in fh:
            raw = raw.strip()
            if not raw:
                continue
            title = raw.partition('**')[0]   # safe split using your '**' delimiter
            titles.append(title)
    return titles

titles = load_titles('movies.txt')
selection = choicebox('Choose a movie', 'Movie Catalog', choices=titles)
# selection will be None if the user cancels

Notes and quick tips:

  • Use with open(...) so files always close.
  • partition('**') avoids a ValueError if a record does not have exactly three parts.
  • If you want to display whole records in the list, format each record into one string (for example, join fields with " - ") so choicebox still receives a list of strings.
  • Handle the None return (user cancelled). For long-term storage, consider CSV or JSON instead of ad-hoc delimiters to make parsing more reliable.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.