trouble with tkinter, with source
walter hanagriff
walter111 at structurex.net
Mon Jun 26 13:47:04 EDT 2000
this is just a framework i am using as a simplified test case for adding
tkinter to my main program
The first class makes the first frame of the program giving the user 3
options, whichever option he chooses opens up a second frame from the
second class, but they just keep piling up, i want it so that if an
options frame is there when they
pick another frame, the first options frame will disappear
i can easily delete the main frame from the Main class, but dont know
how to call the frames from the defs in the second class, whether i try
to call them from Main or Step2, so how do i make what i want happen
i think that best explains what i want, any help would be appreciated
------------------------------------------------------
class Main:
# this function makes the first frame for the program
def __init__(self):
frame = Frame(root, width = 300, height = 400)
frame.pack()
Label(frame, text = "this program figures the area, perimeter,
and power of n \n"
"____________________________________________").pack()
self.v = IntVar()
self.v.set("1")
Radiobutton(frame, text = "1 = Find the power of a number",
variable = self.v, value = 1).pack(anchor = W)
Radiobutton(frame, text = "2 = Find the area of a shape",
variable = self.v, value = 2).pack(anchor = W)
Radiobutton(frame, text = "3 = Find the perimeter of a shape",
variable = self.v, value = 3).pack(anchor = W)
next = Button(frame, text = "Next", padx = 10, command =
self.ifpick)
next.pack(side = LEFT, padx = 5)
close = Button(frame, text = "Close", padx = 10, command =
root.destroy)
close.pack(side = LEFT, padx = 5)
# this says which frame to open depending on which radiobutton above
is picked by user
def ifpick(self):
st = Step2()
if self.v.get() == 2 or 3: st.frame2.frame22.destroy
if self.v.get() == 1: st.frame2()
if self.v.get() == 2: st.frame3()
if self.v.get() == 3: st.frame4()
# Destroys frames not needed then displays all but the first frame in
the program
class Step2:
# this frame is for the power of a number, radiobutton option v == 1
def frame2(self):
frame22 = Frame(root, width = 300, height = 410)
frame22.pack()
Label(frame22, text = "this frame is where you put information
to get power of n \n"
"______________________________________________").pack()
# this frame is for the perimeter of a shape, radiobutton option v
== 3
def frame4(self):
frame44 = Frame(root, width = 300, height = 400)
frame44.pack()
Label(frame44, text = "this frame is where you put information
to get the perimeter of a shape \n"
"______________________________________________").pack()
if __name__== '__main__':
root = Tk()
root.title(title)
start = Main()
root.mainloop()
More information about the Python-list
mailing list