Here I continue to teach you how to use the Tkinter GUI module built into Python. I build an application that allows you to input files, edit them and then save them. I specifically show you how to make the following GUI widgets with Tkinter:
If you haven’t seen the previous Tkinter tutorial you should definitely check it out below first. Otherwise this won’t make any sense.
Leave any questions or comments below and here are all of my previous Python Video Tutorial’s:
[adsense]
Important Note
I was going to originally cover Django in this tutorial, but because many of the major hosting companies don’t allow it to be easily installed, I’m going to pass. I’m also going to finish my Python tutorial very soon. The next tutorial will be on one or another of the following subjects:
Vote for your favorite and which ever subject gets the most votes wins!
Here is All the Code from the Python Video Tutorial
from Tkinter import *
import tkinter.messagebox
def openGrades():
f= open(“studentgrades.txt”)
aboutStud.delete(1.0,END)
studGradeString = “”
for i in f:
studGradeString += i
aboutStud.insert(END, studGradeString)
f.close()
return
def openRank():
f= open(“studentrank.txt”)
aboutStud.delete(1.0,END)
studGradeString = “”
for i in f:
studGradeString += i
aboutStud.insert(END, studGradeString)
f.close()
return
def openFiles(selection):
if selection == “Student Grades”:
openGrades()
else: openRank()
return
def saveGrades():
gradeUpdate = aboutStud.get(1.0,END)
outToFile = open(‘studentgrades.txt’,’w’)
outToFile.write(gradeUpdate)
outToFile.close()
return
def aboutMe():
tkinter.messagebox.showinfo(“Hello”)
return
app = Tk()
app.title(“Gui Example”)
app.geometry(“560×460+200+200″)
menubar = Menu(app)
filemenu = Menu(menubar,tearoff=0)
filemenu.add_command(label=”Open Grades”,command=openGrades)
filemenu.add_command(label=”Open Rank”, command=openRank)
filemenu.add_separator()
filemenu.add_command(label=”Quit”, command=app.quit)
menubar.add_cascade(label=”File”,menu=filemenu)
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_cascade(label=”About Me”, command=aboutMe)
menubar.add_cascade(label=”Help”,menu=helpmenu)
app.config(menu=menubar)
aboutStud = Text(app)
aboutStud.insert(END, “Select student information above”)
aboutStud.pack()
studFiles = StringVar()
studFiles.set(None)
files = [‘Student Grades’, “Student Rank”]
studDropDown = OptionMenu(app, studFiles, *files, command=openFiles).pack()
button1 = Button(app, text=”Save Grades”, width = 20, command=saveGrades)
button1.pack(side=’bottom’,padx=15,pady=15)
app.mainloop()
Hi,
your training awesome, but small request here, it would be great if show the format of txt [studentgrades and rank] files. And where to locate those files. Bcoz am trying run this on linux, but it always throws error for location path. Its too helpful for me if you can help on this.
Thanks in Advance,
Mak
I’ll upload them in a link on the page, or send me your email and I’ll send the files to you. My email is derekbanas@verizon.net
Thanks Derek, here is my mail id mak.6096@gmail.com
I emailed you all of the code from the whole tutorial
this is a great example. Do you have one where a user can get any file from any directory?
This code can be used to do that. Maybe I’m not understanding your question
Great Staff!
Thanks 🙂 I’m glad you liked it
Hi Derek, would you please make the student grades and rank text files (or their contents) available? Thank you very much!
All of the code from the whole video tutorial is available in a zipped archive on this page Python Video Tutorial. I hope that helps