I'm new to Daniweb and with Python and I'm quite bad with it to be honest D:..
Here is my code...
from Tkinter import *
class App(Frame):
def createWidgets(self):
self.grid()
self.lbspace = Label(self, text="")
self.lbspace.grid(row=0,column=0)
self.lbfirstName = Label(self, text="First Name:", font=("Calibri", 12))
self.lbfirstName.grid(row=1,column=0)
self.firstNameVariable = StringVar()
self.firstName = Entry(self, textvariable=self.firstNameVariable, font=("Calibri", 12))
self.firstName.grid(row=1,column=1)
self.firstNameVariable.set("")
self.lblastName = Label(self, text="Last Name:", font=("Calibri", 12))
self.lblastName.grid(row=2,column=0)
self.lastNameVariable = StringVar()
self.lastName = Entry(self, textvariable=self.lastNameVariable, font=("Calibri", 12))
self.lastName.grid(row=2,column=1)
self.lastNameVariable.set("")
self.lbspace = Label(self, text="")
self.lbspace.grid(row=3,column=0)
self.lbclassOne = Label(self, text="Class 1:", font=("Calibri", 12))
self.lbclassOne.grid(row=4,column=0)
self.classOneVariable = StringVar()
self.classOne = Entry(self, textvariable=self.classOneVariable, font=("Calibri", 12))
self.classOne.grid(row=4,column=1)
self.classOneVariable.set("")
self.lbclassTwo = Label(self, text="Class 2:", font=("Calibri", 12))
self.lbclassTwo.grid(row=5,column=0)
self.classTwoVariable = StringVar()
self.classTwo = Entry(self, textvariable=self.classTwoVariable, font=("Calibri", 12))
self.classTwo.grid(row=5,column=1)
self.classTwoVariable.set("")
self.lbclassThree = Label(self, text="Class 3:", font=("Calibri", 12))
self.lbclassThree.grid(row=6,column=0)
self.classThreeVariable = StringVar()
self.classThree = Entry(self, textvariable=self.classThreeVariable, font=("Calibri", 12))
self.classThree.grid(row=6,column=1)
self.classThreeVariable.set("")
self.lbclassFour = Label(self, text="Class 4:", font=("Calibri", 12))
self.lbclassFour.grid(row=7,column=0)
self.classFourVariable = StringVar()
self.classFour = Entry(self, textvariable=self.classFourVariable, font=("Calibri", 12))
self.classFour.grid(row=7,column=1)
self.classFourVariable.set("")
self.lbclassFive = Label(self, text="Class 5:", font=("Calibri", 12))
self.lbclassFive.grid(row=8,column=0)
self.classFiveVariable = StringVar()
self.classFive = Entry(self, textvariable=self.classFiveVariable, font=("Calibri", 12))
self.classFive.grid(row=8,column=1)
self.classFiveVariable.set("")
def __init__(self, master=None):
Frame.__init__(self, master)
self.createWidgets()
frame = Frame()
menu = Menu(root)
root.config(menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label='File', menu=filemenu)
filemenu.add_command(label='Open')
filemenu.add_command(label='Save', command=savefile)
filemenu.add_command(label='Quit', command=frame.quit)
infomenu = Menu(menu)
menu.add_cascade(label='About...', menu=infomenu)
infomenu.add_command(label='About Student Information Program', command=about)
def savefile(self):
import time
text_file=open((self.firstNameVariable.get()) + (self.lastNameVariable.get()) + 'infosave.txt', 'w')
now = time.localtime(time.time())
text_file.write("Date is: " +time.asctime(now))
#("\n") is a new line command for text file
text_file.write("\n")
text_file.write(str(self.firstNameVariable.get()))
text_file.write("\n")
text_file.write(str(self.lastNameVariable.get()))
text_file.write("\n")
text_file.write(str(self.classOneVariable.get()))
text_file.write("\n")
text_file.write(str(self.classTwoVariable.get()))
text_file.write("\n")
text_file.write(str(self.classThreeVariable.get()))
text_file.write("\n")
text_file.write(str(self.classFourVariable.get()))
text_file.write("\n")
text_file.write(str(self.classFiveVariable.get()))
text_file.close()
def about():
print("By ...")
root = Tk()
app = App()
app.master.title("Student Information Program")
app.master.minsize(290,250)
root.mainloop()
root.destroy()
Can't get the save to work comes up with um...
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python25\lib\lib-tk\Tkinter.py", line 1414, in __call__
return self.func(*args)
TypeError: savefile() takes exactly 1 argument (0 given)
Can anyone help me please? I wouldn't mind any advice on improvements :D.