help with tkinter coding
John Grayson
johngrayson at home.com
Sat Jul 15 09:54:28 EDT 2000
In article <396FDD54.E2DD84FF at structurex.net>,
walter hanagriff <walter111 at structurex.net> wrote:
> i got this file from a person on the list not too long ago, thanks for
> this, it is better then what i was thinking of before
> just 2 questions:
> first, how can i make the frame that is to the right of the first
one
> appear on the bottom of it instead
> second, how do i write more then just a label into the second frame,
> in the second frame is going to be a new set of options depending on
> which option was picked in the first frame, so how do i do that?
> this code works as a standalone
>
> -- File test.py
> #!/usr/bin/python
> from Tkinter import *
>
> class Main:
> def __init__(self, root):
> # The top label.
> text = 'this program figures the area, perimeter, and power of
> n'
> text = text + '\n' + '_'*len(text)
> Label(root, text=text).pack(side=TOP, fill=X)
>
> # The 'main' panel to command the option frame to show.
> self.var = StringVar()
> self.var.set('power')
> main = Frame(root, bd=2, relief=SUNKEN)
> Radiobutton(main, text="1 = Find the power of a number",
> value='power',
> command=self.update_frame,
> variable=self.var).pack(anchor=W)
> Radiobutton(main, text="2 = Find the area of a shape",
> value='area',
> command=self.update_frame,
> variable=self.var).pack(anchor=W)
> Radiobutton(main, text="3 = Find the perimeter of a shape",
> value='perim',
> command=self.update_frame,
> variable=self.var).pack(anchor=W)
> Button(main, text="Close", command=root.destroy).pack(padx=10,
> pady=10)
> main.pack(side=LEFT, padx=5, pady=5)
>
> # Create 3 frames, one for each option.
> self.frames = { 'power': Frame(root),
> 'area': Frame(root),
> 'perim': Frame(root) }
>
> # Populate the option frames at your convenience.
> prefix = 'this frame is where you put information to get '
> list = (('power', 'power of n'),
> ('area', 'the area of a shape'),
> ('perim', 'the perimeter of a shape'))
> for (frame_name, text) in list:
> frame = self.frames[frame_name]
> text = prefix + text
> text = text + '\n' + '_'*len(text)
> Label(frame, text=text).pack(expand=YES, fill=BOTH)
>
> # We start with one frame.
> self.update_frame()
>
> def update_frame(self):
> # Unpack every option frame.
> for n in self.frames.keys(): self.frames[n].pack_forget()
> # Pack the current option frame.
> self.frames[self.var.get()].pack(side=RIGHT)
>
> if __name__== '__main__':
> root = Tk()
> root.title('test')
> start = Main(root)
> root.mainloop()
> -- End of file
>
> I throw up your class Func and swept a little your code. Hope this
helps
> ?
>
> Regards,
> Jerome
>
>
It just happens that one of the sample chapters for Python
and Tkinter Programming is on geometry managers. It might
help you understand how the Packer works...
http://www.manning.com/Grayson/chapt05.pdf
John Grayson
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list