July 2002
Intermediate to advanced
608 pages
15h 46m
English
Credit: Magnus Lie Hetland, Alex Martelli
You want to write a simple GUI that can be deployed on just about any toolkit the end user prefers, including Tkinter, wxPython, Swing with Jython, curses-based text I/O, and many others.
The anygui package lets you do this. For
example, here’s an anygui-based
GUI implementation of
chmod:
import sys, os from anygui import * filename = sys.argv[1] # file whose permissions we study and modify # main-level stuff app = Application( ) win = Window(title='chmod '+filename, size=(280,175)) # headers for CheckBoxes and Labels types = 'Read Write Execute'.split( ) people = 'User Group Others'.split( ) # Create and place CheckBoxes and Labels cbx = {} x, y = 10, 0 for p in people: lbl = Label(text=p) lbl.geometry = x, y+10, 80, 15 win.add(lbl) cbx[p] = {} for t in types: y += 35 cbx[p][t] = CheckBox(text=t) cbx[p][t].geometry = x, y, 80, 25 win.add(cbx[p][t]) x += 90; y = 0 # Set the CheckBoxes' values def refresh( ): mode, mask = os.stat(filename)[0], 256 for p in people: for t in types: cbx[p][t].on = mode & mask mask = mask >> 1 # initial setting of checkbox values refresh( ) # callbacks for button clicks def chmod( ): mode, mask = 0, 256 for p in people: for t in types: if cbx[p][t].on: mode = mode | mask mask = mask >> 1 os.chmod(filename, mode) # reset checkbox values refresh( ) def chmod_and_exit( ): chmod( ) sys.exit( ) # Make and add the buttons opt = Options(y=140, ...Read now
Unlock full access