Having problems using Tkinter
viv1tyagi at gmail.com
viv1tyagi at gmail.com
Tue Jul 1 06:13:42 EDT 2008
Hi everyone ! ! !
I'm just a month old in the world of Python and trying to develop an
application using Tkinter in which a new window pops out on a
particular button press.The code for this new window is in
"AddKlas.py" file.
The problem is all the content of the new window is overwritten on
the previous window.
Below is the code of the two files
PLEASE help me out ! ! ! !
#1st file
#Klass.py
from Tkinter import *
import AddKlass
class Klass(Frame):
def __init__(self):
self.labels()
self.buttons()
self.menubuttons()
self.scrollandcanvas()
def labels(self):
label1=Label(relief='groove',text=" Class
Id",width=20,anchor=W)
label1.grid(row=0,column=0)
label2=Label(relief='groove',text=" Class
Name",width=20,anchor=W)
label2.grid(row=0,column=1)
label3=Label(relief='groove',text=" Class Room
No.",width=20,anchor=W)
label3.grid(row=0,column=2)
label4=Label(relief='groove',text=" Category
Id",width=80,anchor=W)
label4.grid(row=0,column=3)
def buttons(self):
button1=Button(text="Add",width=10,command=self.CallAdd)
button1.grid(row=2,column=5)
button2=Button(text="View",width=10,state=DISABLED)
button2.grid(row=3,column=5)
button3=Button(text="Next",width=10,state=DISABLED)
button3.grid(row=4,column=5)
def menubuttons(self):
menubutton=Menubutton(text="Options",width=10,relief="raised")
menubutton.grid(row=5,column=5)
menubutton.menu=Menu(menubutton)
menubutton["menu"]=menubutton.menu
menubutton.menu.add_command(label="Modify")
menubutton.menu.add_command(label="Delete")
def scrollandcanvas(self):
yscroll=Scrollbar()
yscroll.grid(row=1,column=4,rowspan=7,sticky=N+S)
canva=Canvas(bg="#fff",yscrollcommand=yscroll.set)
canva.grid(row=1,column=0,rowspan=7,columnspan=4,sticky=N+E+S
+W)
def CallAdd(self):
AddKlass.root=Tk()
AddKlass.AddKlas()
AddKlass.root.focus_force()
AddKlass.root.geometry("275x250")
AddKlass.root.title("Add Class Information")
AddKlass.root.resizable(width=False,height=False)
AddKlass.root.mainloop()
root=Tk()
app = Klass()
root.geometry("960x300")
root.title("Class Information")
root.resizable(width=False,height=False)
root.mainloop()
#2nd file
#AddKlass.py
from Tkinter import *
class AddKlas(Frame):
#root=None
def __init__(self):
self.labels()
self.buttons()
self.entry()
def labels(self):
label1=Label(relief='flat',text=" Class
Id :",height=3,width=20)
label1.grid()
label2=Label(relief='flat',text=" Class
Name :",height=3,width=20)
label2.grid()
label3=Label(relief='flat',text=" Class Room
No. :",height=3,width=20)
label3.grid()
label4=Label(relief='flat',text=" Category
Id :",height=3,width=20)
label4.grid()
def buttons(self):
button1=Button(text="Add",width=10,state=DISABLED)
button1.grid(row=5,column=0)
button2=Button(text="Cancel",width=10,command=self.quit)
button2.grid(row=5,column=1)
def entry(self):
entry1=Entry() #by default width =20
entry1.grid(row=0,column=1)
entry2=Entry()
entry2.grid(row=1,column=1)
entry3=Entry()
entry3.grid(row=2,column=1)
entry4=Entry()
entry4.grid(row=3,column=1)
#root=Tk()
#app = AddKlas()
#root.geometry("275x250")
#root.title("Add Class Information")
#root.resizable(width=False,height=False)
#root.mainloop()
More information about the Python-list
mailing list