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,p arent):
Tk.__init__(sel f,parent)
self.parent=par ent
self.initialize ()
def initialize(self ):
label=Label(sel f, text="Toplevel Practice").pack (side=TOP)
button1=Button( self,text="Chil d
1",command=self .openchild1).pa ck(side=LEFT)
button2=Button( self,text="Chil d
2",command=self .openchild2).pa ck(side=LEFT)
self.resizable( width=NO,height =YES)
self.geometry(' 300x300')
def openchild1(self ):
c1 =
Toplevel(self,b g="#aabbcc",hei ght=300,width=3 00,borderwidth= 1)
c1.title("Child One")
c1.resizable(wi dth=NO,height=N O)
F = Frame(c1,height =40,width=300)
F.pack(side=TOP ,fill=X,expand= 1)
llb=Label(F,tex t="Enter command..")
llb.pack(side=L EFT,padx=1)
ent = Entry(F,width=5 0)
ent.pack(side=L EFT,padx=2,expa nd=1)
bCl = Button(F,text=" Clear Text",command=s elf.clearentry)
bCl.pack(side=L EFT,padx=2, pady=0)
bQt = Button(F,text=" Quit", command=F.quit)
bQt.pack(side=R IGHT,padx=1, pady=0)
F1=Frame(c1,rel ief=SUNKEN,heig ht=330,width=30 0)
txt=Text(F1)
scr=Scrollbar(F 1,orient=VERTIC AL,command=txt. yview,bg="green ",width=20)
txt.insert(END, "inside txt...")
txt.config(yscr ollcommand=scr. set)
F1.pack(side=TO P,fill=X,expand =1)
txt.pack(side=L EFT,fill=BOTH,p adx=1)
scr.pack(side=R IGHT,fill=Y)
F2=Frame(c1,hei ght=30,width=30 0,relief=RAISED )
F2.pack(side=BO TTOM,fill=X,exp and=1)
llb1=Label(F2,t ext=" Low Down statusbar")
llb1.pack(side= LEFT)
def clearentry(self ):
self.ent.delete (0,END)
def openchild2(self ):
c2 =
Toplevel(self,b g="red",height= 200,width=200,b orderwidth=1)
c2.geometry('20 0x200')
c2.resizable(wi dth=NO,height=N O)
c2.title("Child Two")
Label(c2, text="This is a regular toplevel
window.").pack( side=TOP)
if __name__=="__ma in__":
obj=toplevel1(N one)
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,p arent):
Tk.__init__(sel f,parent)
self.parent=par ent
self.initialize ()
def initialize(self ):
label=Label(sel f, text="Toplevel Practice").pack (side=TOP)
button1=Button( self,text="Chil d
1",command=self .openchild1).pa ck(side=LEFT)
button2=Button( self,text="Chil d
2",command=self .openchild2).pa ck(side=LEFT)
self.resizable( width=NO,height =YES)
self.geometry(' 300x300')
def openchild1(self ):
c1 =
Toplevel(self,b g="#aabbcc",hei ght=300,width=3 00,borderwidth= 1)
c1.title("Child One")
c1.resizable(wi dth=NO,height=N O)
F = Frame(c1,height =40,width=300)
F.pack(side=TOP ,fill=X,expand= 1)
llb=Label(F,tex t="Enter command..")
llb.pack(side=L EFT,padx=1)
ent = Entry(F,width=5 0)
ent.pack(side=L EFT,padx=2,expa nd=1)
bCl = Button(F,text=" Clear Text",command=s elf.clearentry)
bCl.pack(side=L EFT,padx=2, pady=0)
bQt = Button(F,text=" Quit", command=F.quit)
bQt.pack(side=R IGHT,padx=1, pady=0)
F1=Frame(c1,rel ief=SUNKEN,heig ht=330,width=30 0)
txt=Text(F1)
scr=Scrollbar(F 1,orient=VERTIC AL,command=txt. yview,bg="green ",width=20)
txt.insert(END, "inside txt...")
txt.config(yscr ollcommand=scr. set)
F1.pack(side=TO P,fill=X,expand =1)
txt.pack(side=L EFT,fill=BOTH,p adx=1)
scr.pack(side=R IGHT,fill=Y)
F2=Frame(c1,hei ght=30,width=30 0,relief=RAISED )
F2.pack(side=BO TTOM,fill=X,exp and=1)
llb1=Label(F2,t ext=" Low Down statusbar")
llb1.pack(side= LEFT)
def clearentry(self ):
self.ent.delete (0,END)
def openchild2(self ):
c2 =
Toplevel(self,b g="red",height= 200,width=200,b orderwidth=1)
c2.geometry('20 0x200')
c2.resizable(wi dth=NO,height=N O)
c2.title("Child Two")
Label(c2, text="This is a regular toplevel
window.").pack( side=TOP)
if __name__=="__ma in__":
obj=toplevel1(N one)
obj.title('Main Window')
obj.mainloop()