Index: Demo/tkinter/matt/canvas-w-widget-draw-el.py =================================================================== --- Demo/tkinter/matt/canvas-w-widget-draw-el.py (revision 63812) +++ Demo/tkinter/matt/canvas-w-widget-draw-el.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # this file demonstrates the creation of widgets as part of a canvas object Index: Demo/tkinter/matt/not-what-you-might-think-2.py =================================================================== --- Demo/tkinter/matt/not-what-you-might-think-2.py (revision 63812) +++ Demo/tkinter/matt/not-what-you-might-think-2.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * class Test(Frame): Index: Demo/tkinter/matt/menu-simple.py =================================================================== --- Demo/tkinter/matt/menu-simple.py (revision 63812) +++ Demo/tkinter/matt/menu-simple.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # some vocabulary to keep from getting confused. This terminology # is something I cooked up for this file, but follows the man pages Index: Demo/tkinter/matt/printing-coords-of-items.py =================================================================== --- Demo/tkinter/matt/printing-coords-of-items.py (revision 63812) +++ Demo/tkinter/matt/printing-coords-of-items.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # this file demonstrates the creation of widgets as part of a canvas object @@ -35,7 +35,7 @@ # the "current" tag is applied to the object the cursor is over. # this happens automatically. self.draw.itemconfig(CURRENT, fill="red") - print(self.draw.coords(CURRENT)) + print(list(self.draw.coords(CURRENT))) def mouseLeave(self, event): # the "current" tag is applied to the object the cursor is over. Index: Demo/tkinter/matt/canvas-moving-w-mouse.py =================================================================== --- Demo/tkinter/matt/canvas-moving-w-mouse.py (revision 63812) +++ Demo/tkinter/matt/canvas-moving-w-mouse.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # this file demonstrates the movement of a single canvas item under mouse control Index: Demo/tkinter/matt/00-HELLO-WORLD.py =================================================================== --- Demo/tkinter/matt/00-HELLO-WORLD.py (revision 63812) +++ Demo/tkinter/matt/00-HELLO-WORLD.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # note that there is no explicit call to start Tk. # Tkinter is smart enough to start the system if it's not already going. Index: Demo/tkinter/matt/canvas-mult-item-sel.py =================================================================== --- Demo/tkinter/matt/canvas-mult-item-sel.py (revision 63812) +++ Demo/tkinter/matt/canvas-mult-item-sel.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # allows moving dots with multiple selection. Index: Demo/tkinter/matt/window-creation-more.py =================================================================== --- Demo/tkinter/matt/window-creation-more.py (revision 63812) +++ Demo/tkinter/matt/window-creation-more.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # this shows how to create a new window with a button in it # that can create new windows Index: Demo/tkinter/matt/subclass-existing-widgets.py =================================================================== --- Demo/tkinter/matt/subclass-existing-widgets.py (revision 63812) +++ Demo/tkinter/matt/subclass-existing-widgets.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # This is a program that makes a simple two button application Index: Demo/tkinter/matt/animation-w-velocity-ctrl.py =================================================================== --- Demo/tkinter/matt/animation-w-velocity-ctrl.py (revision 63812) +++ Demo/tkinter/matt/animation-w-velocity-ctrl.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # this is the same as simple-demo-1.py, but uses # subclassing. Index: Demo/tkinter/matt/two-radio-groups.py =================================================================== --- Demo/tkinter/matt/two-radio-groups.py (revision 63812) +++ Demo/tkinter/matt/two-radio-groups.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # The way to think about this is that each radio button menu # controls a different variable -- clicking on one of the Index: Demo/tkinter/matt/window-creation-w-location.py =================================================================== --- Demo/tkinter/matt/window-creation-w-location.py (revision 63812) +++ Demo/tkinter/matt/window-creation-w-location.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * import sys ##sys.path.append("/users/mjc4y/projects/python/tkinter/utils") Index: Demo/tkinter/matt/canvas-demo-simple.py =================================================================== --- Demo/tkinter/matt/canvas-demo-simple.py (revision 63812) +++ Demo/tkinter/matt/canvas-demo-simple.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # this program creates a canvas and puts a single polygon on the canvas Index: Demo/tkinter/matt/canvas-reading-tag-info.py =================================================================== --- Demo/tkinter/matt/canvas-reading-tag-info.py (revision 63812) +++ Demo/tkinter/matt/canvas-reading-tag-info.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * class Test(Frame): Index: Demo/tkinter/matt/menu-all-types-of-entries.py =================================================================== --- Demo/tkinter/matt/menu-all-types-of-entries.py (revision 63812) +++ Demo/tkinter/matt/menu-all-types-of-entries.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # some vocabulary to keep from getting confused. This terminology # is something I cooked up for this file, but follows the man pages Index: Demo/tkinter/matt/packer-and-placer-together.py =================================================================== --- Demo/tkinter/matt/packer-and-placer-together.py (revision 63812) +++ Demo/tkinter/matt/packer-and-placer-together.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # This is a program that tests the placer geom manager in conjunction with # the packer. The background (green) is packed, while the widget inside is placed Index: Demo/tkinter/matt/canvas-with-scrollbars.py =================================================================== --- Demo/tkinter/matt/canvas-with-scrollbars.py (revision 63812) +++ Demo/tkinter/matt/canvas-with-scrollbars.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # This example program creates a scroling canvas, and demonstrates # how to tie scrollbars and canvses together. The mechanism Index: Demo/tkinter/matt/entry-simple.py =================================================================== --- Demo/tkinter/matt/entry-simple.py (revision 63812) +++ Demo/tkinter/matt/entry-simple.py (working copy) @@ -1,5 +1,4 @@ -from Tkinter import * -import string +from tkinter import * # This program shows how to use a simple type-in box Index: Demo/tkinter/matt/rubber-band-box-demo-1.py =================================================================== --- Demo/tkinter/matt/rubber-band-box-demo-1.py (revision 63812) +++ Demo/tkinter/matt/rubber-band-box-demo-1.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * class Test(Frame): def printit(self): Index: Demo/tkinter/matt/not-what-you-might-think-1.py =================================================================== --- Demo/tkinter/matt/not-what-you-might-think-1.py (revision 63812) +++ Demo/tkinter/matt/not-what-you-might-think-1.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * class Test(Frame): Index: Demo/tkinter/matt/packer-simple.py =================================================================== --- Demo/tkinter/matt/packer-simple.py (revision 63812) +++ Demo/tkinter/matt/packer-simple.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * class Test(Frame): Index: Demo/tkinter/matt/placer-simple.py =================================================================== --- Demo/tkinter/matt/placer-simple.py (revision 63812) +++ Demo/tkinter/matt/placer-simple.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # This is a program that tests the placer geom manager Index: Demo/tkinter/matt/canvas-gridding.py =================================================================== --- Demo/tkinter/matt/canvas-gridding.py (revision 63812) +++ Demo/tkinter/matt/canvas-gridding.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # this is the same as simple-demo-1.py, but uses # subclassing. Index: Demo/tkinter/matt/window-creation-simple.py =================================================================== --- Demo/tkinter/matt/window-creation-simple.py (revision 63812) +++ Demo/tkinter/matt/window-creation-simple.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # this shows how to spawn off new windows at a button press Index: Demo/tkinter/matt/entry-with-shared-variable.py =================================================================== --- Demo/tkinter/matt/entry-with-shared-variable.py (revision 63812) +++ Demo/tkinter/matt/entry-with-shared-variable.py (working copy) @@ -1,5 +1,4 @@ -from Tkinter import * -import string +from tkinter import * # This program shows how to make a typein box shadow a program variable. @@ -35,7 +34,7 @@ # because it's being looked at by the entry widget, changing # the variable changes the entry widget display automatically. # the strange get/set operators are clunky, true... - str = string.upper(self.contents.get()) + str = self.contents.get().upper() self.contents.set(str) def print_contents(self, event): Index: Demo/tkinter/matt/slider-demo-1.py =================================================================== --- Demo/tkinter/matt/slider-demo-1.py (revision 63812) +++ Demo/tkinter/matt/slider-demo-1.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # shows how to make a slider, set and get its value under program control Index: Demo/tkinter/matt/animation-simple.py =================================================================== --- Demo/tkinter/matt/animation-simple.py (revision 63812) +++ Demo/tkinter/matt/animation-simple.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # This program shows how to use the "after" function to make animation. Index: Demo/tkinter/matt/bind-w-mult-calls-p-type.py =================================================================== --- Demo/tkinter/matt/bind-w-mult-calls-p-type.py (revision 63812) +++ Demo/tkinter/matt/bind-w-mult-calls-p-type.py (working copy) @@ -1,5 +1,4 @@ -from Tkinter import * -import string +from tkinter import * # This program shows how to use a simple type-in box Index: Demo/tkinter/matt/canvas-moving-or-creating.py =================================================================== --- Demo/tkinter/matt/canvas-moving-or-creating.py (revision 63812) +++ Demo/tkinter/matt/canvas-moving-or-creating.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # this file demonstrates a more sophisticated movement -- # move dots or create new ones if you click outside the dots Index: Demo/tkinter/matt/radiobutton-simple.py =================================================================== --- Demo/tkinter/matt/radiobutton-simple.py (revision 63812) +++ Demo/tkinter/matt/radiobutton-simple.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # This is a demo program that shows how to # create radio buttons and how to get other widgets to Index: Demo/tkinter/matt/pong-demo-1.py =================================================================== --- Demo/tkinter/matt/pong-demo-1.py (revision 63812) +++ Demo/tkinter/matt/pong-demo-1.py (working copy) @@ -1,8 +1,5 @@ -from Tkinter import * +from tkinter import * -import string - - class Pong(Frame): def createWidgets(self): self.QUIT = Button(self, text='QUIT', foreground='red', Index: Demo/tkinter/matt/killing-window-w-wm.py =================================================================== --- Demo/tkinter/matt/killing-window-w-wm.py (revision 63812) +++ Demo/tkinter/matt/killing-window-w-wm.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * # This file shows how to trap the killing of a window # when the user uses window manager menus (typ. upper left hand corner Index: Demo/tkinter/matt/dialog-box.py =================================================================== --- Demo/tkinter/matt/dialog-box.py (revision 63812) +++ Demo/tkinter/matt/dialog-box.py (working copy) @@ -1,5 +1,5 @@ -from Tkinter import * -from Dialog import Dialog +from tkinter import * +from tkinter.dialog import Dialog # this shows how to create a new window with a button in it # that can create new windows Index: Demo/tkinter/matt/rubber-line-demo-1.py =================================================================== --- Demo/tkinter/matt/rubber-line-demo-1.py (revision 63812) +++ Demo/tkinter/matt/rubber-line-demo-1.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * class Test(Frame): def printit(self): Index: Demo/tkinter/guido/AttrDialog.py =================================================================== --- Demo/tkinter/guido/AttrDialog.py (revision 63812) +++ Demo/tkinter/guido/AttrDialog.py (working copy) @@ -12,7 +12,7 @@ # -- totally static, though different between PackDialog and WidgetDialog # (but even that could be unified) -from Tkinter import * +from tkinter import * class Option: @@ -120,7 +120,7 @@ cl = self.classes[c] except KeyError: cl = 'unknown' - if type(cl) == TupleType: + if type(cl) == tuple: cl = self.enumoption elif cl == 'boolean': cl = self.booleanoption @@ -435,12 +435,11 @@ list.app = app # Pass it on to handler def opendialogs(e): - import string list = e.widget sel = list.curselection() for i in sel: item = list.get(i) - widget = string.split(item)[0] + widget = item.split()[0] RemoteWidgetDialog(list, list.app, widget) if widget == '.': continue try: Index: Demo/tkinter/guido/solitaire.py =================================================================== --- Demo/tkinter/guido/solitaire.py (revision 63812) +++ Demo/tkinter/guido/solitaire.py (working copy) @@ -25,19 +25,10 @@ import math import random -from Tkinter import * -from Canvas import Rectangle, CanvasText, Group, Window +from tkinter import * +from canvasevents import Group -# Fix a bug in Canvas.Group as distributed in Python 1.4. The -# distributed bind() method is broken. Rather than asking you to fix -# the source, we fix it here by deriving a subclass: - -class Group(Group): - def bind(self, sequence=None, command=None): - return self.canvas.tag_bind(self.id, sequence, command) - - # Constants determining the size and lay-out of cards and stacks. We # work in a "grid" where each card/stack is surrounded by MARGIN # pixels of space on each side, so adjacent stacks are separated by @@ -165,20 +156,21 @@ self.face_shown = 0 self.x = self.y = 0 + self.canvas = canvas self.group = Group(canvas) text = "%s %s" % (VALNAMES[value], suit) - self.__text = CanvasText(canvas, CARDWIDTH/2, 0, - anchor=N, fill=self.color, text=text) + self.__text = canvas.create_text(CARDWIDTH // 2, 0, anchor=N, + fill=self.color, text=text) self.group.addtag_withtag(self.__text) - self.__rect = Rectangle(canvas, 0, 0, CARDWIDTH, CARDHEIGHT, - outline='black', fill='white') + self.__rect = canvas.create_rectangle(0, 0, CARDWIDTH, CARDHEIGHT, + outline='black', fill='white') self.group.addtag_withtag(self.__rect) - self.__back = Rectangle(canvas, MARGIN, MARGIN, - CARDWIDTH-MARGIN, CARDHEIGHT-MARGIN, - outline='black', fill='blue') + self.__back = canvas.create_rectangle(MARGIN, MARGIN, + CARDWIDTH - MARGIN, CARDHEIGHT - MARGIN, outline='black', + fill='blue') self.group.addtag_withtag(self.__back) def __repr__(self): @@ -202,15 +194,15 @@ def showface(self): """Turn the card's face up.""" self.tkraise() - self.__rect.tkraise() - self.__text.tkraise() + self.canvas.tag_raise(self.__rect) + self.canvas.tag_raise(self.__text) self.face_shown = 1 def showback(self): """Turn the card's face down.""" self.tkraise() - self.__rect.tkraise() - self.__back.tkraise() + self.canvas.tag_raise(self.__rect) + self.canvas.tag_raise(self.__back) self.face_shown = 0 @@ -400,10 +392,9 @@ """ def makebottom(self): - bottom = Rectangle(self.game.canvas, - self.x, self.y, - self.x+CARDWIDTH, self.y+CARDHEIGHT, - outline='black', fill=BACKGROUND) + bottom = self.game.canvas.create_rectangle(self.x, self.y, + self.x + CARDWIDTH, self.y + CARDHEIGHT, outline='black', + fill=BACKGROUND) self.group.addtag_withtag(bottom) def fill(self): @@ -435,7 +426,7 @@ def randperm(n): """Function returning a random permutation of range(n).""" - r = range(n) + r = list(range(n)) x = [] while r: i = random.choice(r) @@ -478,10 +469,8 @@ class SuitStack(OpenStack): def makebottom(self): - bottom = Rectangle(self.game.canvas, - self.x, self.y, - self.x+CARDWIDTH, self.y+CARDHEIGHT, - outline='black', fill='') + bottom = self.game.canvas.create_rectangle(self.x, self.y, + self.x + CARDWIDTH, self.y + CARDHEIGHT, outline='black', fill='') def userclickhandler(self): pass @@ -540,8 +529,8 @@ background=BACKGROUND, activebackground="green", command=self.deal) - Window(self.canvas, MARGIN, 3*YSPACING + 20, - window=self.dealbutton, anchor=SW) + self.canvas.create_window(MARGIN, 3 * YSPACING + 20, + window=self.dealbutton, anchor=SW) x = MARGIN y = MARGIN Index: Demo/tkinter/guido/kill.py =================================================================== --- Demo/tkinter/guido/kill.py (revision 63812) +++ Demo/tkinter/guido/kill.py (working copy) @@ -1,9 +1,7 @@ #! /usr/bin/env python # Tkinter interface to Linux `kill' command. -from Tkinter import * -from string import splitfields -from string import split +from tkinter import * import subprocess import os @@ -26,13 +24,13 @@ ('Hex', '-X', 0)] def kill(self, selected): c = self.format_list[self.format.get()][2] - pid = split(selected)[c] + pid = select.split()[c] os.system('kill -9 ' + pid) self.do_update() def do_update(self): name, option, column = self.format_list[self.format.get()] s = subprocess.getoutput('ps -w ' + option) - list = splitfields(s, '\n') + list = s.split('\n') self.header.set(list[0]) del list[0] y = self.frame.vscroll.get()[0] Index: Demo/tkinter/guido/listtree.py =================================================================== --- Demo/tkinter/guido/listtree.py (revision 63812) +++ Demo/tkinter/guido/listtree.py (working copy) @@ -1,9 +1,8 @@ # List a remote app's widget tree (names and classes only) import sys -import string -from Tkinter import * +from tkinter import * def listtree(master, app): list = Listbox(master, name='list') @@ -13,8 +12,6 @@ def listnodes(list, app, widget, level): klass = list.send(app, 'winfo', 'class', widget) -## i = string.rindex(widget, '.') -## list.insert(END, '%s%s (%s)' % ((level-1)*'. ', widget[i:], klass)) list.insert(END, '%s (%s)' % (widget, klass)) children = list.tk.splitlist( list.send(app, 'winfo', 'children', widget)) Index: Demo/tkinter/guido/optionmenu.py =================================================================== --- Demo/tkinter/guido/optionmenu.py (revision 63812) +++ Demo/tkinter/guido/optionmenu.py (working copy) @@ -1,6 +1,6 @@ # option menu sample (Fredrik Lundh, September 1997) -from Tkinter import * +from tkinter import * root = Tk() Index: Demo/tkinter/guido/sortvisu.py =================================================================== --- Demo/tkinter/guido/sortvisu.py (revision 63812) +++ Demo/tkinter/guido/sortvisu.py (working copy) @@ -19,8 +19,7 @@ """ -from Tkinter import * -from Canvas import Line, Rectangle +from tkinter import * import random @@ -31,6 +30,9 @@ class Array: + class Cancelled(BaseException): + pass + def __init__(self, master, data=None): self.master = master self.frame = Frame(self.master) @@ -41,9 +43,9 @@ self.canvas.pack() self.report = Label(self.frame) self.report.pack() - self.left = Line(self.canvas, 0, 0, 0, 0) - self.right = Line(self.canvas, 0, 0, 0, 0) - self.pivot = Line(self.canvas, 0, 0, 0, 0) + self.left = self.canvas.create_line(0, 0, 0, 0) + self.right = self.canvas.create_line(0, 0, 0, 0) + self.pivot = self.canvas.create_line(0, 0, 0, 0) self.items = [] self.size = self.maxvalue = 0 if data: @@ -82,8 +84,6 @@ if self.in_mainloop: self.master.quit() - Cancelled = "Array.Cancelled" # Exception - def wait(self, msecs): if self.speed == "fastest": msecs = 0 @@ -110,15 +110,15 @@ for i in range(self.size): item = self.items[i] if first <= i < last: - item.item.config(fill='red') + self.canvas.itemconfig(item, fill='red') else: - item.item.config(fill='orange') + self.canvas.itemconfig(item, fill='orange') self.hide_left_right_pivot() def hide_partition(self): for i in range(self.size): item = self.items[i] - item.item.config(fill='red') + self.canvas.itemconfig(item, fill='red') self.hide_left_right_pivot() def show_left(self, left): @@ -127,7 +127,7 @@ return x1, y1, x2, y2 = self.items[left].position() ## top, bot = HIRO - self.left.coords([(x1-2, 0), (x1-2, 9999)]) + self.canvas.coords(self.left, (x1 - 2, 0, x1 - 2, 9999)) self.master.update() def show_right(self, right): @@ -135,7 +135,7 @@ self.hide_right() return x1, y1, x2, y2 = self.items[right].position() - self.right.coords(((x2+2, 0), (x2+2, 9999))) + self.canvas.coords(self.right, (x2 + 2, 0, x2 + 2, 9999)) self.master.update() def hide_left_right_pivot(self): @@ -144,17 +144,17 @@ self.hide_pivot() def hide_left(self): - self.left.coords(((0, 0), (0, 0))) + self.canvas.coords(self.left, (0, 0, 0, 0)) def hide_right(self): - self.right.coords(((0, 0), (0, 0))) + self.canvas.coords(self.right, (0, 0, 0, 0)) def show_pivot(self, pivot): x1, y1, x2, y2 = self.items[pivot].position() - self.pivot.coords(((0, y1-2), (9999, y1-2))) + self.canvas.coords(self.pivot, (0, y1 - 2, 9999, y1 - 2)) def hide_pivot(self): - self.pivot.coords(((0, 0), (0, 0))) + self.canvas.coords(self.pivot, (0, 0, 0, 0)) def swap(self, i, j): if i == j: return @@ -199,12 +199,13 @@ self.array = array self.index = index self.value = value + self.canvas = array.canvas x1, y1, x2, y2 = self.position() - self.item = Rectangle(array.canvas, x1, y1, x2, y2, - fill='red', outline='black', width=1) - self.item.bind('', self.mouse_down) - self.item.bind('', self.mouse_move) - self.item.bind('', self.mouse_up) + self.item = array.canvas.create_rectangle(x1, y1, x2, y2, + fill='red', outline='black', width=1) + array.canvas.tag_bind(self.item, '', self.mouse_down) + array.canvas.tag_bind(self.item, '', self.mouse_move) + array.canvas.tag_bind(self.item, '', self.mouse_up) def delete(self): item = self.item @@ -235,7 +236,7 @@ self.array.items[here], self.array.items[i] = other, self self.index = i x1, y1, x2, y2 = self.position() - self.item.coords(((x1, y1), (x2, y2))) + self.canvas.coords(self.item, (x1, y1, x2, y2)) other.setindex(here) def setindex(self, index): @@ -249,7 +250,7 @@ trajectory = interpolate(oldpts, newpts, nsteps) self.item.tkraise() for pts in trajectory: - self.item.coords((pts[:2], pts[2:])) + self.canvas.coords(self.item, pts) self.array.wait(50) def swapwith(self, other): @@ -262,45 +263,45 @@ self.index, other.index = other.index, self.index mynewpts = self.position() othernewpts = other.position() - myfill = self.item['fill'] - otherfill = other.item['fill'] - self.item.config(fill='green') - other.item.config(fill='yellow') + myfill = self.canvas.itemcget(self.item, 'fill') + otherfill = self.canvas.itemcget(other.item, 'fill') + self.canvas.itemconfig(self.item, fill='green') + self.canvas.itemconfig(other.item, fill='yellow') self.array.master.update() if self.array.speed == "single-step": - self.item.coords((mynewpts[:2], mynewpts[2:])) - other.item.coords((othernewpts[:2], othernewpts[2:])) + self.canvas.coords(self.item, mynewpts) + self.canvas.coords(other.item, othernewpts) self.array.master.update() - self.item.config(fill=myfill) - other.item.config(fill=otherfill) + self.canvas.itemconfig(self.item, fill=myfill) + self.canvas.itemconfig(other.item, fill=otherfill) self.array.wait(0) return mytrajectory = interpolate(myoldpts, mynewpts, nsteps) othertrajectory = interpolate(otheroldpts, othernewpts, nsteps) if self.value > other.value: - self.item.tkraise() - other.item.tkraise() + self.canvas.tag_raise(self.item) + self.canvas.tag_raise(other.item) else: - other.item.tkraise() - self.item.tkraise() + self.canvas.tag_raise(other.item) + self.canvas.tag_raise(self.item) try: for i in range(len(mytrajectory)): mypts = mytrajectory[i] otherpts = othertrajectory[i] - self.item.coords((mypts[:2], mypts[2:])) - other.item.coords((otherpts[:2], otherpts[2:])) + self.canvas.coords(self.item, mypts) + self.canvas.coords(other.item, otherpts) self.array.wait(50) finally: mypts = mytrajectory[-1] otherpts = othertrajectory[-1] - self.item.coords((mypts[:2], mypts[2:])) - other.item.coords((otherpts[:2], otherpts[2:])) - self.item.config(fill=myfill) - other.item.config(fill=otherfill) + self.canvas.coords(self.item, mypts) + self.canvas.coords(other.item, otherpts) + self.canvas.itemconfig(self.item, fill=myfill) + self.canvas.itemconfig(other.item, fill=otherfill) def compareto(self, other): - myfill = self.item['fill'] - otherfill = other.item['fill'] + myfill = self.canvas.itemcget(self.item, 'fill') + otherfill = self.canvas.itemcget(other.item, 'fill') outcome = cmp(self.value, other.value) if outcome < 0: myflash = 'white' @@ -311,12 +312,12 @@ else: myflash = otherflash = 'grey' try: - self.item.config(fill=myflash) - other.item.config(fill=otherflash) + self.canvas.itemconfig(self.item, fill=myflash) + self.canvas.itemconfig(other.item, fill=otherflash) self.array.wait(500) finally: - self.item.config(fill=myfill) - other.item.config(fill=otherfill) + self.canvas.itemconfig(self.item, fill=myfill) + self.canvas.itemconfig(other.item, fill=otherfill) return outcome def position(self): @@ -429,7 +430,7 @@ j = j-1 continue array.message("Choosing pivot") - j, i, k = first, (first+last)/2, last-1 + j, i, k = first, (first+last)//2, last-1 if array.compare(k, i) < 0: array.swap(k, i) if array.compare(k, j) < 0: @@ -519,7 +520,7 @@ self.v_size = MyIntVar(self.master, self) self.v_size.set(size) - sizes = [1, 2, 3, 4] + range(5, 55, 5) + sizes = [1, 2, 3, 4] + list(range(5, 55, 5)) if self.size not in sizes: sizes.append(self.size) sizes.sort() Index: Demo/tkinter/guido/electrons.py =================================================================== --- Demo/tkinter/guido/electrons.py (revision 63812) +++ Demo/tkinter/guido/electrons.py (working copy) @@ -11,7 +11,7 @@ # /usr/include/X11/bitmaps for samples); it is displayed as the # background of the animation. Default is no bitmap. -from Tkinter import * +from tkinter import * import random @@ -62,11 +62,11 @@ # Main program def main(): - import sys, string + import sys # First argument is number of electrons, default 30 if sys.argv[1:]: - n = string.atoi(sys.argv[1]) + n = int(sys.argv[1]) else: n = 30 Index: Demo/tkinter/guido/hanoi.py =================================================================== --- Demo/tkinter/guido/hanoi.py (revision 63812) +++ Demo/tkinter/guido/hanoi.py (working copy) @@ -10,7 +10,7 @@ # background of the animation. Default is no bitmap. # This uses Steen Lumholt's Tk interface -from Tkinter import * +from tkinter import * # Basic Towers-of-Hanoi algorithm: move n pieces from a to b, using c @@ -101,10 +101,10 @@ # Move it towards peg b bx1, by1, bx2, by2 = c.bbox(self.pegs[b]) - newcenter = (bx1+bx2)/2 + newcenter = (bx1+bx2)//2 while 1: x1, y1, x2, y2 = c.bbox(p) - center = (x1+x2)/2 + center = (x1+x2)//2 if center == newcenter: break if center > newcenter: c.move(p, -1, 0) else: c.move(p, 1, 0) @@ -125,11 +125,11 @@ # Main program def main(): - import sys, string + import sys # First argument is number of pegs, default 4 if sys.argv[1:]: - n = string.atoi(sys.argv[1]) + n = int(sys.argv[1]) else: n = 4 Index: Demo/tkinter/guido/ShellWindow.py =================================================================== --- Demo/tkinter/guido/ShellWindow.py (revision 63812) +++ Demo/tkinter/guido/ShellWindow.py (working copy) @@ -1,9 +1,8 @@ import os import sys -import string -from Tkinter import * -from ScrolledText import ScrolledText -from Dialog import Dialog +from tkinter import * +from tkinter.scrolledtext import ScrolledText +from tkinter.dialog import Dialog import signal BUFSIZE = 512 @@ -17,7 +16,7 @@ except KeyError: shell = '/bin/sh' shell = shell + ' -i' - args = string.split(shell) + args = shell.split() shell = args[0] ScrolledText.__init__(self, master, **cnf) @@ -132,7 +131,7 @@ return pid, c2pread, p2cwrite def test(): - shell = string.join(sys.argv[1:]) + shell = ' '.join(sys.argv[1: ]) root = Tk() root.minsize(1, 1) if shell: Index: Demo/tkinter/guido/dialog.py =================================================================== --- Demo/tkinter/guido/dialog.py (revision 63812) +++ Demo/tkinter/guido/dialog.py (working copy) @@ -4,7 +4,7 @@ # optional bitmap, and any number of buttons. # Cf. Ousterhout, Tcl and the Tk Toolkit, Figs. 27.2-3, pp. 269-270. -from Tkinter import * +from tkinter import * import sys @@ -24,8 +24,7 @@ # 2. Fill the top part with the bitmap and message. - msg = Message(top, width='3i', text=text, - font='-Adobe-Times-Medium-R-Normal-*-180-*') + msg = Message(top, width='3i', text=text) msg.pack(side=RIGHT, expand=1, fill=BOTH, padx='3m', pady='3m') if bitmap: bm = Label(top, bitmap=bitmap) Index: Demo/tkinter/guido/canvasevents.py =================================================================== --- Demo/tkinter/guido/canvasevents.py (revision 63812) +++ Demo/tkinter/guido/canvasevents.py (working copy) @@ -1,18 +1,42 @@ #! /usr/bin/env python -from Tkinter import * -from Canvas import Oval, Group, CanvasText +from tkinter import * +# Since Canvas.Group is no longer present, the following class reproduces +# a subset of the old Group class that is used by this app. -# Fix a bug in Canvas.Group as distributed in Python 1.4. The -# distributed bind() method is broken. This is what should be used: +class Group: + def __init__(self, canvas, tag=None): + if tag is None: + tag = 'Group%d' % id(self) -class Group(Group): - def bind(self, sequence=None, command=None): - return self.canvas.tag_bind(self.id, sequence, command) + self.tag = self.id = tag + self.canvas = canvas + self.canvas.dtag(self.tag) + def __str__(self): + return self.tag + + def _do(self, cmd, *args): + return self.canvas.tk.call(self.canvas._w, cmd, self.tag, *args) + + def addtag_withtag(self, tagOrId): + self._do('addtag', 'withtag', tagOrId) + + def bind(self, sequence=None, command=None, add=None): + return self.canvas.tag_bind(self.id, sequence, command, add) + + def move(self, x_amount, y_amount): + self._do('move', x_amount, y_amount) + + def dtag(self, tagToDelete=None): + self._do('dtag', tagToDelete) + + def tkraise(self, aboveThis=None): + self._do('raise', aboveThis) + + class Object: - """Base class for composite graphical objects. Objects belong to a canvas, and can be moved around on the canvas. @@ -29,7 +53,6 @@ All instance attributes are public since the derived class may need them. - """ def __init__(self, canvas, x=0, y=0, fill='red', text='object'): @@ -44,12 +67,10 @@ return str(self.group) def createitems(self, fill, text): - self.__oval = Oval(self.canvas, - self.x-20, self.y-10, self.x+20, self.y+10, - fill=fill, width=3) + self.__oval = self.canvas.create_oval(self.x - 20, self.y - 10, + self.x + 20, self.y + 20, fill=fill, width=3) self.group.addtag_withtag(self.__oval) - self.__text = CanvasText(self.canvas, - self.x, self.y, text=text) + self.__text = self.canvas.create_text(self.x, self.y, text=text) self.group.addtag_withtag(self.__text) def moveby(self, dx, dy): @@ -75,18 +96,15 @@ class Bottom(Object): - """An object to serve as the bottom of a pile.""" def createitems(self, *args): - self.__oval = Oval(self.canvas, - self.x-20, self.y-10, self.x+20, self.y+10, - fill='gray', outline='') + self.__oval = self.canvas.create_oval(self.x - 20, self.y - 10, + self.x + 20, self.y + 10, fill='gray', outline='') self.group.addtag_withtag(self.__oval) class Pile: - """A group of graphical objects.""" def __init__(self, canvas, x, y, tag=None): Index: Demo/tkinter/guido/imagedraw.py =================================================================== --- Demo/tkinter/guido/imagedraw.py (revision 63812) +++ Demo/tkinter/guido/imagedraw.py (working copy) @@ -1,6 +1,6 @@ """Draw on top of an image""" -from Tkinter import * +from tkinter import * import sys def main(): Index: Demo/tkinter/guido/switch.py =================================================================== --- Demo/tkinter/guido/switch.py (revision 63812) +++ Demo/tkinter/guido/switch.py (working copy) @@ -1,6 +1,6 @@ # Show how to do switchable panels. -from Tkinter import * +from tkinter import * class App: Index: Demo/tkinter/guido/brownian2.py =================================================================== --- Demo/tkinter/guido/brownian2.py (revision 63812) +++ Demo/tkinter/guido/brownian2.py (working copy) @@ -1,7 +1,7 @@ # Brownian motion -- an example of a NON multi-threaded Tkinter program ;) # By Michele Simoniato, inspired by brownian.py -from Tkinter import * +from tkinter import * import random import sys @@ -32,7 +32,7 @@ yield None def move(particle): # move the particle at random time - particle.next() + next(particle) dt = random.expovariate(LAMBDA) root.after(int(dt*1000), move, particle) Index: Demo/tkinter/guido/rmt.py =================================================================== --- Demo/tkinter/guido/rmt.py (revision 63812) +++ Demo/tkinter/guido/rmt.py (working copy) @@ -11,7 +11,7 @@ # XXX This should be written in a more Python-like style!!! -from Tkinter import * +from tkinter import * import sys # 1. Create basic application structure: menu bar on top of @@ -28,7 +28,7 @@ s.pack(side=RIGHT, fill=Y) t = Text(f, relief=RAISED, borderwidth=2, yscrollcommand=s.set, setgrid=1) t.pack(side=LEFT, fill=BOTH, expand=1) -t.tag_config('bold', font='-Adobe-Courier-Bold-R-Normal-*-120-*') +t.tag_config('bold') s['command'] = t.yview root.title('Tk Remote Controller') Index: Demo/tkinter/guido/hello.py =================================================================== --- Demo/tkinter/guido/hello.py (revision 63812) +++ Demo/tkinter/guido/hello.py (working copy) @@ -1,7 +1,7 @@ # Display hello, world in a button; clicking it quits the program import sys -from Tkinter import * +from tkinter import * def main(): root = Tk() Index: Demo/tkinter/guido/svkill.py =================================================================== --- Demo/tkinter/guido/svkill.py (revision 63812) +++ Demo/tkinter/guido/svkill.py (working copy) @@ -2,13 +2,11 @@ # Tkinter interface to SYSV `ps' and `kill' commands. -from Tkinter import * +from tkinter import * if TkVersion < 4.0: raise ImportError("This version of svkill requires Tk 4.0 or later") -from string import splitfields -from string import split import subprocess import os @@ -40,14 +38,14 @@ ] def kill(self, selected): c = self.format_list[self.format.get()][2] - pid = split(selected)[c] + pid = selected.split()[c] os.system('kill -9 ' + pid) self.do_update() def do_update(self): format = self.format_list[self.format.get()][1] view = self.view_list[self.view.get()][1] s = subprocess.getoutput('ps %s %s' % (view, format)) - list = splitfields(s, '\n') + list = s.split('\n') self.header.set(list[0] + ' ') del list[0] self.frame.list.delete(0, AtEnd()) @@ -97,14 +95,12 @@ self.header = StringVar(self) self.frame.label = Label( self.frame, relief=FLAT, anchor=NW, borderwidth=0, - font='*-Courier-Bold-R-Normal-*-120-*', textvariable=self.header) self.frame.label.pack(fill=Y, anchor=W) self.frame.vscroll = Scrollbar(self.frame, orient=VERTICAL) self.frame.list = Listbox( self.frame, relief=SUNKEN, - font='*-Courier-Medium-R-Normal-*-120-*', width=40, height=10, selectbackground='#eed5b7', selectborderwidth=0, Index: Demo/tkinter/guido/newmenubardemo.py =================================================================== --- Demo/tkinter/guido/newmenubardemo.py (revision 63812) +++ Demo/tkinter/guido/newmenubardemo.py (working copy) @@ -2,7 +2,7 @@ """Play with the new Tk 8.0 toplevel menu option.""" -from Tkinter import * +from tkinter import * class App: Index: Demo/tkinter/guido/ManPage.py =================================================================== --- Demo/tkinter/guido/ManPage.py (revision 63812) +++ Demo/tkinter/guido/ManPage.py (working copy) @@ -1,9 +1,9 @@ # Widget to display a man page import re -from Tkinter import * -from Tkinter import _tkinter -from ScrolledText import ScrolledText +from tkinter import * +from tkinter import _tkinter +from tkinter.scrolledtext import ScrolledText # XXX These fonts may have to be changed to match your system BOLDFONT = '*-Courier-Bold-R-Normal-*-120-*' @@ -107,13 +107,13 @@ # Save this line -- we need one line read-ahead self.buffer = nextline return - if emptyprog.match(self.buffer) >= 0: + if emptyprog.match(self.buffer): # Buffered line was empty -- set a flag self.empty = 1 self.buffer = nextline return textline = self.buffer - if ulprog.match(nextline) >= 0: + if ulprog.match(nextline): # Next line is properties for buffered line propline = nextline self.buffer = None @@ -127,7 +127,7 @@ self.ok = 1 self.empty = 0 return - if footerprog.match(textline) >= 0: + if footerprog.match(textline): # Footer -- start skipping until next non-blank line self.ok = 0 self.empty = 0 Index: Demo/tkinter/guido/tkman.py =================================================================== --- Demo/tkinter/guido/tkman.py (revision 63812) +++ Demo/tkinter/guido/tkman.py (working copy) @@ -2,15 +2,15 @@ # Tk man page browser -- currently only shows the Tcl/Tk man pages -import sys import os -import string import re -from Tkinter import * +import sys +from tkinter import * + from ManPage import ManPage -MANNDIRLIST = ['/depot/sundry/man/mann','/usr/local/man/mann'] -MAN3DIRLIST = ['/depot/sundry/man/man3','/usr/local/man/man3'] +MANNDIRLIST = ['/depot/sundry/man/mann', '/usr/local/man/mann'] +MAN3DIRLIST = ['/depot/sundry/man/man3', '/usr/local/man/man3'] foundmanndir = 0 for dir in MANNDIRLIST: @@ -221,9 +221,9 @@ print('Regex error:', msg) return here = self.text.index(AtInsert()) - lineno = string.atoi(here[:string.find(here, '.')]) + lineno = int(here[:here.find('.')]) end = self.text.index(AtEnd()) - endlineno = string.atoi(end[:string.find(end, '.')]) + endlineno = int(end[:end.find('.')]) wraplineno = lineno found = 0 while 1: @@ -237,9 +237,9 @@ line = self.text.get('%d.0 linestart' % lineno, '%d.0 lineend' % lineno) i = prog.search(line) - if i >= 0: + if i: found = 1 - n = max(1, len(prog.group(0))) + n = max(1, len(i.group(0))) try: self.text.tag_remove('sel', AtSelFirst(), @@ -247,10 +247,10 @@ except TclError: pass self.text.tag_add('sel', - '%d.%d' % (lineno, i), - '%d.%d' % (lineno, i+n)) + '%d.%d' % (lineno, i.start()), + '%d.%d' % (lineno, i.start()+n)) self.text.mark_set(AtInsert(), - '%d.%d' % (lineno, i)) + '%d.%d' % (lineno, i.start())) self.text.yview_pickplace(AtInsert()) break if not found: Index: Demo/tkinter/guido/paint.py =================================================================== --- Demo/tkinter/guido/paint.py (revision 63812) +++ Demo/tkinter/guido/paint.py (working copy) @@ -20,7 +20,7 @@ davem@magnet.com """ -from Tkinter import * +from tkinter import * """paint.py: not exactly a paint program.. just a smooth line drawing demo.""" Index: Demo/tkinter/guido/imageview.py =================================================================== --- Demo/tkinter/guido/imageview.py (revision 63812) +++ Demo/tkinter/guido/imageview.py (working copy) @@ -1,4 +1,4 @@ -from Tkinter import * +from tkinter import * import sys def main(): Index: Demo/tkinter/guido/brownian.py =================================================================== --- Demo/tkinter/guido/brownian.py (revision 63812) +++ Demo/tkinter/guido/brownian.py (working copy) @@ -1,6 +1,6 @@ # Brownian motion -- an example of a multi-threaded Tkinter program. -from Tkinter import * +from tkinter import * import random import threading import time