我是使用tkinter创建GUI的初学者,所以我决定从制作类似记事本的应用程序开始。现在,我想显示所选文本文件的文件路径,然后将其内容插入另一个Entry框。我的问题是我无法获得OPEN按钮的其他功能的内容。我希望能在这里得到教训/答案,谢谢!
def browsefunc():
filename = askopenfilename()
infile = open(filename, 'r')
content = infile.read()
pathadd = os.path.dirname(filename)+filename
pathlabel.delete(0, END)
pathlabel.insert(0, pathadd)
return content
browsebutton = Button(root, text="Browse", command=browsefunc)
browsebutton.pack()
browsebutton.grid(row=0)
pathlabel = Entry(root, textvariable=pathadd,width=90,)
pathlabel.pack()
pathlabel.grid(row=1)
def openfunc():
global content
data = content
textFile.delete(0, END)
textFile.insert(0,data)
openbutton = Button(root, text="Open Now",command=openfunc)
openbutton.pack()
openbutton.grid(row=2)
scrollText = Scrollbar(root, orient='vertical')
textFile = Text(root, bg='white', width=90, height=29, relief='groove',
wrap='word')
textFile.pack(fill=BOTH, expand=1)
scrollText.config (command=textFile.yview)
scrollText.grid(column=1, row=3,sticky='NS',padx=(1,5),pady=(17,1))
textFile.grid(row=3)
textFile.config(state='disabled')
scrollText.config(command=textFile.yview)