A
Anish Chapagain
Hi!!
I'm trying to program an application which have multiple windows and
is capable of executing method defined inside class of one another, i
tries a simpel frame work here and am creating Toplevel inside method
as the new window to be genereated, and again want another window to
be loaded when the widget inside toplevel is executed as
necessary..but am feeling lost to either create a class for such new
window or write function again..
also, when running clearentry() it is not working...have i missed
something here..
Programming with multiple window is main task for me..so how it can be
done???
the code i tried is here,
from Tkinter import *
import sys
import os
class toplevel1(Tk):
def __init__(self,parent):
Tk.__init__(self,parent)
self.parent=parent
self.initialize()
def initialize(self):
label=Label(self, text="Toplevel Practice").pack(side=TOP)
button1=Button(self,text="Child
1",command=self.openchild1).pack(side=LEFT)
button2=Button(self,text="Child
2",command=self.openchild2).pack(side=LEFT)
self.resizable(width=NO,height=YES)
self.geometry('300x300')
def openchild1(self):
c1 =
Toplevel(self,bg="#aabbcc",height=300,width=300,borderwidth=1)
c1.title("Child One")
c1.resizable(width=NO,height=NO)
F = Frame(c1,height=40,width=300)
F.pack(side=TOP,fill=X,expand=1)
llb=Label(F,text="Enter command..")
llb.pack(side=LEFT,padx=1)
ent = Entry(F,width=50)
ent.pack(side=LEFT,padx=2,expand=1)
bCl = Button(F,text="Clear Text",command=self.clearentry)
bCl.pack(side=LEFT,padx=2, pady=0)
bQt = Button(F,text="Quit", command=F.quit)
bQt.pack(side=RIGHT,padx=1, pady=0)
F1=Frame(c1,relief=SUNKEN,height=330,width=300)
txt=Text(F1)
scr=Scrollbar(F1,orient=VERTICAL,command=txt.yview,bg="green",width=20)
txt.insert(END,"inside txt...")
txt.config(yscrollcommand=scr.set)
F1.pack(side=TOP,fill=X,expand=1)
txt.pack(side=LEFT,fill=BOTH,padx=1)
scr.pack(side=RIGHT,fill=Y)
F2=Frame(c1,height=30,width=300,relief=RAISED)
F2.pack(side=BOTTOM,fill=X,expand=1)
llb1=Label(F2,text=" Low Down statusbar")
llb1.pack(side=LEFT)
def clearentry(self):
self.ent.delete(0,END)
def openchild2(self):
c2 =
Toplevel(self,bg="red",height=200,width=200,borderwidth=1)
c2.geometry('200x200')
c2.resizable(width=NO,height=NO)
c2.title("Child Two")
Label(c2, text="This is a regular toplevel
window.").pack(side=TOP)
if __name__=="__main__":
obj=toplevel1(None)
obj.title('Main Window')
obj.mainloop()
I'm trying to program an application which have multiple windows and
is capable of executing method defined inside class of one another, i
tries a simpel frame work here and am creating Toplevel inside method
as the new window to be genereated, and again want another window to
be loaded when the widget inside toplevel is executed as
necessary..but am feeling lost to either create a class for such new
window or write function again..
also, when running clearentry() it is not working...have i missed
something here..
Programming with multiple window is main task for me..so how it can be
done???
the code i tried is here,
from Tkinter import *
import sys
import os
class toplevel1(Tk):
def __init__(self,parent):
Tk.__init__(self,parent)
self.parent=parent
self.initialize()
def initialize(self):
label=Label(self, text="Toplevel Practice").pack(side=TOP)
button1=Button(self,text="Child
1",command=self.openchild1).pack(side=LEFT)
button2=Button(self,text="Child
2",command=self.openchild2).pack(side=LEFT)
self.resizable(width=NO,height=YES)
self.geometry('300x300')
def openchild1(self):
c1 =
Toplevel(self,bg="#aabbcc",height=300,width=300,borderwidth=1)
c1.title("Child One")
c1.resizable(width=NO,height=NO)
F = Frame(c1,height=40,width=300)
F.pack(side=TOP,fill=X,expand=1)
llb=Label(F,text="Enter command..")
llb.pack(side=LEFT,padx=1)
ent = Entry(F,width=50)
ent.pack(side=LEFT,padx=2,expand=1)
bCl = Button(F,text="Clear Text",command=self.clearentry)
bCl.pack(side=LEFT,padx=2, pady=0)
bQt = Button(F,text="Quit", command=F.quit)
bQt.pack(side=RIGHT,padx=1, pady=0)
F1=Frame(c1,relief=SUNKEN,height=330,width=300)
txt=Text(F1)
scr=Scrollbar(F1,orient=VERTICAL,command=txt.yview,bg="green",width=20)
txt.insert(END,"inside txt...")
txt.config(yscrollcommand=scr.set)
F1.pack(side=TOP,fill=X,expand=1)
txt.pack(side=LEFT,fill=BOTH,padx=1)
scr.pack(side=RIGHT,fill=Y)
F2=Frame(c1,height=30,width=300,relief=RAISED)
F2.pack(side=BOTTOM,fill=X,expand=1)
llb1=Label(F2,text=" Low Down statusbar")
llb1.pack(side=LEFT)
def clearentry(self):
self.ent.delete(0,END)
def openchild2(self):
c2 =
Toplevel(self,bg="red",height=200,width=200,borderwidth=1)
c2.geometry('200x200')
c2.resizable(width=NO,height=NO)
c2.title("Child Two")
Label(c2, text="This is a regular toplevel
window.").pack(side=TOP)
if __name__=="__main__":
obj=toplevel1(None)
obj.title('Main Window')
obj.mainloop()