3

Relatively new to coding in general, and have been trying to create a simple chat client for Python. Trying to work the GUI, and have encountered the problem shown below.

I have a functioning GUI and use the "example.get()" function to retrieve the string text from an entry box. The program then prints the text to the command prompt (Just to prove it's been retrieved) and then should place it in a text box, however it gives me a "Nonetype" error. Code is below. Does anyone have any idea how to fix this?

Thanks

from tkinter import *

#Create GUI
root=Tk()
root.title("Chat test")
root.geometry("450x450+300+300")

#Declare variables
msg=StringVar()

#Get and post text to chat log
def postaction():
    msg1=msg.get()
    print(msg1)
    chatlog.insert(INSERT,msg1+'\n')
    root.mainloop()

#Build GUI components
chatlog=Text(root, height=10, state=DISABLED).pack(side=TOP, fill=X)
entry=Entry(root, textvariable=msg).pack(side=BOTTOM, fill=X)
button=Button(root, command=postaction, text="Button").pack()

1 Answer 1

12

The .pack method of a widget always returns None. So, you need to place the calls to .pack on their own line:

chatlog=Text(root, height=10, state=DISABLED)
chatlog.pack(side=TOP, fill=X)
entry=Entry(root, textvariable=msg)
entry.pack(side=BOTTOM, fill=X)
button=Button(root, command=postaction, text="Button")
button.pack()
Sign up to request clarification or add additional context in comments.

3 Comments

This fixed the Nonetype error, however it still doesn't post to the chatlog. Any ideas?
@QuarterGeekster - Oh, sorry. I didn't see that. You can fix that problem by simply removing the state=DISABLED part of the line where you make the textbox. Having it makes the textbox unusable.
Thanks a lot! Now I can finally move on to other things!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.