[Tutor] A few newbie questions about Tkinter (disregard previous)

Denis spirou@aragne.com
Tue, 15 Aug 2000 03:05:26 +0200


--qDbXVdCdHGoSgWSk
Content-Type: text/plain; charset=us-ascii

Le Mon, Aug 14, 2000 at 12:10:41PM -0700, Joseph Stubenrauch pianota:
> Any suggestions?  Perhaps just some pseudo-code to
> give me some pointers?
> 

Do you use Tkinter variables ? (StringVar)
Are you sure dialogs are the best way ?
Why not a single form with a left and right side, a status and so on ?

> presses "tab"?
set the takefocus property of your desired widgets to 1 if needed

I attach some "cut&try" code so that you can play with it.

Have fun,


P.S.
You could also ckeck http://www.browsebooks.com/Grayson/
You'll find the source code of the book.
Have a look at Example_12_1.py : it's about a Navigation class ...
and try to find someone to offer you the book :-)
 
-- 
Denis FRERE
P3B    : Club Free-Pytho-Linuxien Caroloregien http://www.p3b.org
Aragne : Internet - Reseaux - Formations  http://www.aragne.com

--qDbXVdCdHGoSgWSk
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: attachment; filename="takefocus.py"
Content-Transfer-Encoding: 8bit

#!/usr/bin/env python
#
#------------------------------------------------
# Sample program to show the takefocus property
# and some other features of Tkinter
#
# by Spirou  
# http://www.p3b.org
#------------------------------------------------
#

from Tkinter import *

root = Tk()

# callbacks
def shownext(event):
    """
    show the next word in the book
    """
    global pointer
    pointer = pointer + 1
    if pointer > len(book)-1:
        pointer = 1
    var1.set(book[pointer])
    var2.set('')
    return var1.get()
    
def die(event):
    """
    Quit 
    """
    root.quit()

# a book and a pointer
book = ["Mot franšais",
   "programmer", "variable", "objet", "afficher", "dictionnaire"]
pointer = 0

# and two Tkvariables for the Entries
var1 = StringVar()
var1.set(book[pointer])
var2 = StringVar()
var2.set("English Translation")

# a big superior frame
f1 = Frame(root, 
        bg="darkslateblue",
        highlightthickness = 2,
        highlightcolor = "blue",
        width=400, height=240
     )
# a small one for the buttons
f2 = Frame(root, 
        bg="darkslateblue",
        highlightthickness = 2,
        highlightcolor = "blue",
        width=400, height=60
     )
# 2 frames in the big superior, with the entries
fa = Frame(f1,
	bg="lightslateblue",
##        takefocus = 1,
        highlightthickness = 2,
        highlightcolor = "violet",
        width=100, height=240
     )
fb = Frame(f1,
	bg="lightslateblue",
##        takefocus = 1,
        highlightthickness = 2,
        highlightcolor = "violet",
        width=100, height=240
     )
f1.pack(side=TOP, expand=YES, fill=BOTH)
f2.pack(side=TOP, expand=NO, fill=X)
fa.pack(side=LEFT, expand=YES, fill=BOTH)
fb.pack(side=RIGHT, expand=YES, fill=BOTH)
t1 = Entry(fa,
	textvariable = var1,
        takefocus = 0, # so, it won't get the focus
        highlightthickness = 1,
        highlightcolor = "red",
        width=25
     )

t2 = Entry(fb,
	textvariable = var2,
##        takefocus = 1, # this one will get the focus (default value)
        highlightthickness = 1,
        highlightcolor = "red",
        width=25
     )
t1.pack()
t2.pack()

# two buttons, one to move the cursor ahead, the other to quit
b1 = Button(f2,
	text="next",
        highlightthickness = 2,
        highlightcolor = "red"
     )
b1.bind('<Button-1>', shownext)
b1.bind('<KeyPress Return>', shownext)
b1.bind('<KeyPress space>', shownext)

b2 = Button(f2,
	text="quit",
        highlightthickness = 2,
        highlightcolor = "red"
     )
b2.bind('<Button-1>', die)
b2.bind('<KeyPress Return>', die)
b2.bind('<KeyPress space>', die)

b2.pack(side=RIGHT)
b1.pack(side=RIGHT)

# and go
root.wm_title("Tabs & Tkinter Variables")
root.wm_minsize(400, 300)
root.mainloop()

--qDbXVdCdHGoSgWSk--