-1

I have had an issue with this piece of code from awhile back, it's part of a GCSE mock and I have currently finished the working code (with text only) but I would like to expand it so that it has a nice GUI. I'm getting some issues with updating my sentence variables within the code. Anyone with any suggestions for me please do explain how I can fix it.

    #GCSE TASK WITH GUI
    import tkinter
    from tkinter import *
    from tkinter import ttk

    var_sentence = ("default")

    window = tkinter.Tk()
    window.resizable(width=FALSE, height=FALSE)
    window.title("Sentence")
    window.geometry("400x300")
    window.wm_iconbitmap("applicationlogo.ico")

    file = open("sentencedata.txt","w")
    file = open("sentencedata.txt","r")

    def update_sentence():
        var_sentence = sentence.get()


    def submit():
        file.write(sentence)
        print ("")

    def findword():
        messagebox.showinfo("Found!")
        print ("Found")


    sentencetext = tkinter.Label(window, fg="purple" ,text="Enter Sentence: ")
    sentence = tkinter.Entry(window)
    sentencebutton = tkinter.Button(text="Submit", fg="red" , command=update_sentence)

    findword = tkinter.Label(window, fg="purple" ,text="Enter Word To Find: ")
    wordtofind = tkinter.Entry(window)
    findwordbutton = tkinter.Button(text="Find!", fg="red" ,command=findword)


    usersentence = sentence.get()
    usersentence = tkinter.Label(window,text=sentence)


    shape = Canvas (bg="grey", cursor="arrow", width="400", height="8")
    shape2 = Canvas (bg="grey", cursor="arrow", width="400", height="8")

    #Packing & Ordering Moduales
    sentencetext.pack()
    sentence.pack()
    sentencebutton.pack()

    shape.pack()

    findword.pack()
    wordtofind.pack()
    findwordbutton.pack()
    usersentence.pack()

    shape2.pack()

    window.mainloop()
Tom
  • 15
  • 1
  • 1
  • 8
  • 1
    "Not working" is not an informative description of the problem. Please edit your question to include the expected and actual behavior, as well as any error messages. – user2085282 Oct 21 '15 at 18:21
  • I notice that you did not close your file reader, this may not be the problem, but can raise some exceptions – Adi Oct 21 '15 at 18:39
  • 1
    "updating my sentence variables within the code" might make sense to you, but I have no idea what that means. Please describe some specific inputs, actual outputs, and how the actual outputs are different than what you expect. – Bryan Oakley Oct 21 '15 at 18:41

1 Answers1

1

If I understand your question right, you want to display the entered text in the usersentence label.

Changing update_sentence() function to what is shown below will archive the desired effect.

def update_sentence():
    var_sentence = sentence.get()
    usersentence.config(text=var_sentence)

usersentence never gets updated because you only set it once when the program starts this was the problem.

Adi
  • 5,560
  • 1
  • 24
  • 37
  • Thanks, you have fixed my issue I've been looking for quite some time now and you have finally fixed it. Once again Thanks. – Tom Oct 21 '15 at 20:18
  • Firstly it was hard to figure out the what the actual question was, so in the future when you post a question please be more elaborate about what the problem is. Thanks – Adi Oct 22 '15 at 03:57