我使用Tkinter模块在Python中创建了一个基于GUI的程序。我创建了一个名为self.f_text的文本小部件,但是当我调用它的get方法时,我得到一个非常不寻常的错误。我检查了代码4时代,我无法找到任何错误。如果有人能回答我的问题,那就太棒了。
from Tkinter import *
class Application(Frame):
def __init__(self,master):
Frame.__init__(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
Label(self,text = "Welcome to medicaps ki pathshala.").grid(row = 0,column = 0,columnspan = 2,sticky = W)
Label(self,text = "Choose the options which you feel are correct.").grid(row = 1,column = 0,columnspan = 2,sticky = W)
Label(self,text = "Name :- ").grid(row = 2,column = 0,sticky = W)
self.n_entry = Entry(self)
self.n_entry.grid(row = 2,column = 1,sticky = W)
Label(self,text = "Colleges :- ").grid(row = 3,column = 0,sticky = W)
self.cont_college = StringVar()
colleges = ["Medicaps","Acropolis","SVCE"]
colum = 1
for college in colleges:
Radiobutton(self,text = college,variable = self.cont_college,value = college).grid(row = 3,column = colum,sticky = W)
colum += 1
Label(self,text = "Badass teachers :- ").grid(row = 4,column = 0,sticky = W)
self.cont_neelam = BooleanVar()
self.cont_kautuk = BooleanVar()
self.cont_jeetu = BooleanVar()
Checkbutton(self,text = "Neelam Dubey",variable = self.cont_neelam).grid(row = 4,column = 1,sticky = W)
Checkbutton(self,text = "Kautuk Sharma",variable = self.cont_kautuk).grid(row = 4,column = 2,sticky = W)
Checkbutton(self,text = "Jitendra bhawsar",variable = self.cont_jeetu).grid(row = 4,column = 3,sticky = W)
Label(self,text = "Affiliation :- ").grid(row = 5,column = 0,sticky = W)
self.cont_aff = StringVar()
affiliation = ["Medicaps","DAVV","Anna University","RGPV"]
colum = 1
for aff in affiliation:
Radiobutton(self,text = aff,value = aff,variable = self.cont_aff).grid(row = 5,column = colum,sticky = W)
colum += 1
Label(self,text = "Raggers :- ").grid(row = 6,column = 0,sticky = W)
self.r_entry = Entry(self)
self.r_entry.grid(row = 6,column = 1,sticky = W)
Label(self,text = "How do you feel :- ").grid(row = 7,column = 0,sticky = W)
self.f_text = Text(self,width = 35,height = 26,wrap = WORD)
self.f_text.grid(row = 7,column = 1,columnspan = 2)
Button(self,text = "Click for story ",command = self.reveal).grid(row = 8,column = 0,sticky = W)
self.text = Text(self,width = 35,height = 26,wrap = WORD)
self.text.grid(row = 9,column = 0,columnspan = 2,sticky = W)
def reveal(self):
name = self.n_entry.get()
college = self.cont_college.get()
teachers = ""
if self.cont_neelam.get():
teachers += "Neelam Dubey, "
if self.cont_kautuk.get():
teachers += "Kautuk Sharma, "
if self.cont_jeetu.get():
teachers += "Jeetendra Bhawsar "
affiliation = self.cont_aff.get()
raggers = self.r_entry.get()
feel = self.f_text.get()
self.f_text.delete()
story = "Once opon a time there was a college named " + college.title() + " .Which was affiliated to " + affiliation + "."
story += "There were some badass teachers in it, whose names were " + teachers + "."
story += "Every year some students took admission in it ,but one day an extraordinary student took admission ."
story += "The name of the student was " + name + "."
story += "And this is what he felt about the college ,' " + feel + " '."
story += "\nTHATS ALL FOLKS....."
self.text.delete(0.0,END)
self.text.insert(0.0,story)
def main():
root = Tk()
root.geometry("400x250")
root.title("Medicaps ki paathshala")
frame = Application(root)
root.mainloop()
main()