[Tkinter-discuss] A Hello and a Question

Michael Lange klappnase at web.de
Thu May 4 11:41:58 CEST 2006

On Wed, 03 May 2006 15:21:03 +0000
"Peter Lacroix" <pjlacroix at hotmail.com> wrote:

> Thanks to Olivier for the sample structure. I think I understand it although 
> I'm not very familiar with 'lambda'. Now Cameron has brought up a good 
> point. By the way, this is an end-of-semester project for students. I am 
> teaching Python for the first time to a high school class - so my knowledge 
> is certainly limited. We have created a few simple programs but all have 
> been command line. So ultimately the goal is simply to learn what GUIs are 
> and play around, not to create anything professional. But Cameron's point is 
> interesting. That is, have a set of tabs that display where in the process 
> of the program the user is. This way they know how far they easily have a 
> visual hold on how far they have to go and how far they've been. Of course, 
> these tabs would not be clickable. I would want the buttons to cause the 
> switch. I think I like that idea. Does it fit with the structure that 
> Olivier offered below?
> import Tkinter as tk
> def change_frame(i, j):
>     frames[i].pack_forget()
>     frames[j].pack()
> frames = []
> r = tk.Tk()
> #frames that you fill with your widgets
> f1 = tk.Frame(r)
> tk.Button(f1, command=lambda :change_frame(0,1),text='go to step 1').pack()
> f2 = tk.Frame(r)
> tk.Button(f2, command=lambda :change_frame(1,2),text='go to step 2').pack()
> f3 = tk.Frame(r)
> tk.Label(f3, text = 'step2').pack()
> frames = [f1,f2,f3]
> f1.pack()
> r.mainloop()

Maybe you could use a Pmw.NoteBook and disable the tab buttons, like this (untested):

from Tkinter import *
import Pmw

root = Tk()

nb = Pmw.NoteBook(root)
nb.pack(side='top', fill='both', expand=1)

def next_page():
    pages = nb.pagenames()
    current = nb.getcurselection()
    # maybe more testing and changing the button's text here
    if current == pages[-1]:

b = Button(root, text='Next page', command=next_page)

firstpage = nb.add('firstpage', tab_text='First page', tab_state='disabled', tab_disabledforeground='black')
(...)# add widgets and more pages


I hope this helps


More information about the Tkinter-discuss mailing list