python - Tkinter's root returns an attribute error -
from tkinter import * import random root=tk() answers=["it certain. ", "signs point yes.","my sources no.","not chance.","dumb question ,ask another."] error_messages=["was question ,stupid head", "you know squiggly thing dot underneath? question mark","you forgot question mark","dident teach use question mark?"] all_numbers=["err,42?","please ask me proper question ","that looked number me? ","i talking robot not calculator","i need question in words ,stupid head"] def submit(*ignore): """this function takes in question , produces answer""" question=ask_box.get() if question =="": message=("you didn't ask anything") elif question.isdigit: message=random.choice(all_numbers) elif not question.endwith("?"): message=random.choice(error_message) elif not " "in questions: message=random.choice=("i dont 1 word questions") display(message) def display(message): """simple text display function.takes string""" ask_box.delete(0,end) txt["state"]="normal" txt.delete(0,0,end) txt.insert(0,0,message) txt["state"]="disabled" #set gui root.tk() root.resizable(0,0) app=frame(root) app.grid() root.bind('<return>',submit) root.title("magic 8 ball") root.geometry("220x325") ask_lbl=label(app,text="ask yes or no question") ask_lbl.grid(row=0,column=0,columnspan=3,pady=5) ask_box=entry(app,width=30) ask_box.grid(row=1,column=0,columnspan=3,pady=5) ask_box.focus_force() shake=button(app,text="shake 8 ball") shake["command"]=submit shake.grid(row=2,column=1,pady=5) txt=text(app,width=30,height=3,wrap=word,state=disabled) txt.grid(row=4,column=0,columnspan=3,pady=5) #start loop root.mainloop()
this code supposed work magic 8 ball tkinter keeps returning attribute error can explain why, thanks.the program given me project cant tkinter run program
just remove line root.tk()
. supposed root=tk()
, did @ beginning of code, it's not necessary.
Comments
Post a Comment