def __init__(self): l = """An arrow and a vertical scale are displayed below. If you click or drag mouse button 1 in the scale, you can change the size of the arrow.""" DemoWindow.__init__(self, l, demo_path('vscale.py')) self.frame = Frame(self, width=300, height=500) self.frame.pack(expand=Y, fill=BOTH) self.scale = Scale(self.frame, orient='vertical', length=300, from_=0, to_=250, tickinterval=50, command=self.scale_callback) self.scale.pack(side=LEFT, expand=Y, fill=Y, padx=30, pady=30) self.canvas = Canvas(self.frame, height=300, width=200) self.canvas.pack(side=LEFT, expand=Y, fill=BOTH) options = {'fill': 'cyan', 'outline': 'darkblue'} self.arrow = self.canvas.create_polygon(*self.arrow_points(50)) self.canvas.itemconfigure(self.arrow, options) self.scale.set(50)
def __init__(self): l = """hree different entries are displayed below. You can add characters by pointing, clicking and typing. The normal Motif editing characters are supported, along with many Emacs bindings. For example, Backspace and Control-h delete the character to the left of the insertion cursor and Delete and Control-d delete the chararacter to the right of the insertion cursor. For entries that are too large to fit in the window all at once, you can scan through the entries by dragging with mouse button2 pressed. """ DemoWindow.__init__(self, l, 'entry1.py') frame = Frame(self) frame.pack(expand=YES, fill=BOTH) w1 = Entry(frame) w2 = Entry(frame) w3 = Entry(frame) for w in w1, w2, w3: w.pack(side=TOP, fill=X, padx=5, pady=10) w1.insert(0, 'Initial value') w2.insert(0, "This entry contains a value much too long ") w2.insert(END, "to fit in the window at one time, so long in fact") w2.insert(END, " that you will have to scroll or scan to see the end.")
def __init__(self): l="""Enter a file name in the entry box or click on the \"Browse\" buttons to select a file name using the file selection dialog.""" DemoWindow.__init__(self, l, demo_path('filebox.py') ) frame = Frame(self); frame.pack(side=TOP,expand=YES,fill=BOTH) l1 = Label(frame, text='Select a file to open:') l2 = Label(frame, text='Select a file to save:') e1=Entry(frame); self.e1=e1 e2=Entry(frame); self.e2=e2 b1 = Button(frame, text='Browse...', command=self.selectopen_callback) b2 = Button(frame, text='Browse...', command=self.selectsave_callback) frame.rowconfigure(1,pad=10, weight=1) for r in (0,1,2): frame.columnconfigure(r, pad=5) # insert elements in the container rnum=0 for r in ( (l1, e1, b1), (l2, e2, b2) ): cnum=0 for w in r : w.grid(row=rnum, column=cnum ) cnum=cnum+1 rnum=rnum+1 self.mvar=IntVar(self) mb = Checkbutton(self, text='Use motif stile dialog', variable=self.mvar, command=self.changestyle_callback ) mb.pack(side=TOP, expand=YES, fill=X )
def __init__( self ): l=""" Choose the icon and type option of the message box. Then press the \"Message Box\" button to see the message box. """ DemoWindow.__init__(self,l,demo_path('msgbox.py')) frame=Frame(self);frame.pack(expand=Y, fill=BOTH) #create the two option panels middleframe=Frame(frame); middleframe.pack(side=TOP,fill=X) p1 = OptionPanel(middleframe,'Icon', 'error', 'window', 'question', 'warning') p1.set('error') p1.pack(side=LEFT, expand=YES, fill=BOTH, padx=10, pady=10) p2 = OptionPanel(middleframe,'Type', 'abortretryignore', 'ok', 'okcancel', 'retrycancel', 'yesno' ) p2.set('ok') p2.pack(side=RIGHT, expand=YES, fill=BOTH, padx=10,pady=10) b = Button(frame,text='Open Dialog', command=self.opendialog_callback ) b.pack(side=TOP,fill=X, padx=10) self.p1, self.p2 = p1,p2 # needed by the callback
def __init__(self): l="""The listbox below contains a collection of well-known sayings. You can scan the list using either of the scrollbars or by dragging in the listbox window with button 2 pressed. """ DemoWindow.__init__(self, l, 'sayings.py' ) # create the list frame = Frame(self); frame.pack(expand=YES, fill=Y) list = Listbox(frame, setgrid=1) vbar = Scrollbar(frame,command=list.yview) list['yscrollcommand'] = vbar.set hbar = Scrollbar(frame,command=list.xview,orient='horizontal') list['xscrollcommand'] = hbar.set #pack all toghether frame.rowconfigure(0, weight=1) frame.columnconfigure(0,weight=1) list.grid(row=0,column=0,sticky='nsew') vbar.grid(row=0,column=1,sticky='ns') hbar.grid(row=1,column=0,sticky='ew') # fill the list for i in sayings: list.insert(END,i)
def __init__(self): l = """hree different entries are displayed below. You can add characters by pointing, clicking and typing. The normal Motif editing characters are supported, along with many Emacs bindings. For example, Backspace and Control-h delete the character to the left of the insertion cursor and Delete and Control-d delete the chararacter to the right of the insertion cursor. For entries that are too large to fit in the window all at once, you can scan through the entries by dragging with mouse button2 pressed. """ DemoWindow.__init__(self, l, 'entry1.py' ) frame = Frame(self); frame.pack(expand=YES, fill=BOTH) w1 = Entry(frame) w2 = Entry(frame) w3 = Entry(frame) for w in w1,w2,w3: w.pack(side=TOP, fill=X,padx=5, pady=10 ) w1.insert(0, 'Initial value') w2.insert(0,"This entry contains a value much too long ") w2.insert(END,"to fit in the window at one time, so long in fact") w2.insert(END," that you will have to scroll or scan to see the end.")
def __init__(self): l = """ Choose the icon and type option of the message box. Then press the \"Message Box\" button to see the message box. """ DemoWindow.__init__(self, l, demo_path('msgbox.py')) frame = Frame(self) frame.pack(expand=Y, fill=BOTH) #create the two option panels middleframe = Frame(frame) middleframe.pack(side=TOP, fill=X) p1 = OptionPanel(middleframe, 'Icon', 'error', 'window', 'question', 'warning') p1.set('error') p1.pack(side=LEFT, expand=YES, fill=BOTH, padx=10, pady=10) p2 = OptionPanel(middleframe, 'Type', 'abortretryignore', 'ok', 'okcancel', 'retrycancel', 'yesno') p2.set('ok') p2.pack(side=RIGHT, expand=YES, fill=BOTH, padx=10, pady=10) b = Button(frame, text='Open Dialog', command=self.opendialog_callback) b.pack(side=TOP, fill=X, padx=10) self.p1, self.p2 = p1, p2 # needed by the callback
def __init__(self): l = """The listbox below contains a collection of well-known sayings. You can scan the list using either of the scrollbars or by dragging in the listbox window with button 2 pressed. """ DemoWindow.__init__(self, l, 'sayings.py') # create the list frame = Frame(self) frame.pack(expand=YES, fill=Y) list = Listbox(frame, setgrid=1) vbar = Scrollbar(frame, command=list.yview) list['yscrollcommand'] = vbar.set hbar = Scrollbar(frame, command=list.xview, orient='horizontal') list['xscrollcommand'] = hbar.set #pack all toghether frame.rowconfigure(0, weight=1) frame.columnconfigure(0, weight=1) list.grid(row=0, column=0, sticky='nsew') vbar.grid(row=0, column=1, sticky='ns') hbar.grid(row=1, column=0, sticky='ew') # fill the list for i in sayings: list.insert(END, i)
def __init__(self): l = """This window displays all of Tk's built-in bitmaps, along with the names you can use for them in scripts. """ DemoWindow.__init__(self, l, demo_path('bitmap.py')) frame = Frame(self) frame.pack(expand=YES, fill=BOTH, pady=10) list = ('error', 'gray12', 'gray25', 'gray50', 'gray75', 'hourglass', 'info', 'question', 'questhead', 'warning') row = 0 column = 0 for b in list: f = Frame(frame) l1 = Label(f, bitmap=b) l1.pack(side=TOP) l2 = Label(f, text=b) l2.pack(side=BOTTOM) f.grid(row=row, column=column, sticky='ns', padx=10) column = column + 1 if column >= len(list) / 2: row = row + 1 column = 0
def __init__(self): DemoWindow.__init__(self, '', 'text.py' ) frame = Frame(self); frame.pack(expand=Y, fill=BOTH ) text=Text(frame, relief=SUNKEN, bd=2, setgrid=1, height=35); text.pack(side=LEFT, expand=Y, fill=BOTH) bar=Scrollbar(frame); bar.pack(side=LEFT, fill=Y) text['yscrollcommand']=bar.set; bar['command']=text.yview txt = """ This window is a text widget. It displays one or more lines of text and allows you to edit the text. Here is a summary of the things you can do to a text widget: 1. Scrolling. Use the scrollbar to adjust the view in the text window. 2. Scanning. Press mouse button 2 in the text window and drag up or down. This will drag the text at high speed to allow you to scan its contents. 3. Insert text. Press mouse button 1 to set the insertion cursor, then type text. What you type will be added to the widget. 4. Select. Press mouse button 1 and drag to select a range of characters. Once you've released the button, you can adjust the selection by pressing button 1 with the shift key down. This will reset the end of the selection nearest the mouse cursor and you can drag that end of the selection by dragging the mouse before releasing the mouse button. You can double-click to select whole words or triple-click to select whole lines. 5. Delete and replace. To delete text, select the characters you'd like to delete and type Backspace or Delete. Alternatively, you can type new text, in which case it will replace the selected text. 6. Copy the selection. To copy the selection into this window, select what you want to copy (either here or in another application), then click button 2 to copy the selection to the point of the mouse cursor. 7. Edit. Text widgets support the standard Motif editing characters plus many Emacs editing characters. Backspace and Control-h erase the character to the left of the insertion cursor. Delete and Control-d erase the character to the right of the insertion cursor. Meta-backspace deletes the word to the left of the insertion cursor, and Meta-d deletes the word to the right of the insertion cursor. Control-k deletes from the insertion cursor to the end of the line, or it deletes the newline character if that is the only thing left on the line. Control-o opens a new line by inserting a newline character to the right of the insertion cursor. Control-t transposes the two characters on either side of the insertion cursor. 7. Resize the window. This widget has been configured with the "setGrid" option on, so that if you resize the window it will always resize to an even number of characters high and wide. Also, if you make the window narrow you can see that long lines automatically wrap around onto additional lines so that all the information is always visible. """ text.insert('0.0', txt )
def __init__(self): DemoWindow.__init__(self, '', 'tagged-text.py' ) frame = Frame(self); frame.pack(expand=Y, fill=BOTH ) text=Text(frame, relief=SUNKEN, bd=2, setgrid=1, wrap='word', height=35); text.pack(side=LEFT, expand=Y, fill=BOTH) bar=Scrollbar(frame); bar.pack(side=LEFT, fill=Y) text['yscrollcommand']=bar.set; bar['command']=text.yview self.text = text self.tags = range(0,6) # create and binds the tags for t in self.tags: self.text.tag_configure (t) self.text.tag_bind(t, '<Any-Enter>', callit(self.reconfigure_tag, t, 'bold' )) self.text.tag_bind(t, '<Any-Leave>', callit(self.reconfigure_tag, t, 'normal' )) self.text.tag_bind(t, '<1>', callit(self.link_callback, t )) # insert tagged text intro = """ The same tag mechanism that controls display styles in text widgets can also be used to associate Tcl commands with regions of text, so that mouse or keyboard actions on the text cause particular Tcl commands to be invoked. For example, in the text below the descriptions of the canvas demonstrations have been tagged. When you move the mouse over a demo description the description lights up, and when you press button 1 over a description then that particular demonstration is invoked. """ text.insert('0.0', intro ) text.insert( END, '1. Samples of all the different types of items that'+ ' can be created in canvas widgets.', self.tags[0] ) text.insert( END, '\n\n'); text.insert( END, '2. A simple two-dimensional plot that allows you '+ 'to adjust the positions of the data points.', self.tags[1] ) text.insert( END, '\n\n'); text.insert( END, '3. Anchoring and justification modes for text items.', self.tags[2] ) text.insert( END, '\n\n'); text.insert( END, '4. An editor for arrow-head shapes for line items.', self.tags[3] ) text.insert( END, '\n\n'); text.insert( END, '5. A ruler with facilities for editing tab stops.', self.tags[4] ) text.insert( END, '\n\n'); text.insert( END, '6. A grid that demonstrates how canvases can be '+ 'scrolled.', self.tags[5] )
def __init__(self): DemoWindow.__init__(self, '', 'search.py' ) frame = Frame(self); frame.pack(expand=Y, fill=BOTH) # create the controls panel c_frame = Frame(frame); c_frame.pack(side=TOP,expand=Y,fill=X) c_frame.columnconfigure(1, weight=1,minsize=300 ) file_l=Label(c_frame, text='File name:'); file_l.grid(row=0,column=0, sticky='w') self.filevar=StringVar(c_frame) self.file_e=Entry(c_frame, textvariable=self.filevar ); self.file_e.grid(row=0, column=1, sticky='ew') self.file_e.bind('<Return>', self.load_callback ) self.load_b =Button(c_frame, text='Load file', padx=10, command=self.load_callback ) self.load_b.grid(row=0, column=2, sticky='e' ) string_l=Label(c_frame, text='Search string:') string_l.grid(row=1,column=0) self.stringvar=StringVar(c_frame) self.string_e=Entry(c_frame, textvariable=self.stringvar ); self.string_e.grid(row=1, column=1, sticky='ew') self.string_e.bind('<Return>', self.hilight_callback ) self.hilight_b =Button(c_frame, text='Hilight', padx=10, command=self.hilight_callback ) self.hilight_b.grid(row=1, column=2 ) # create the text widget and related scrollbar t_frame = Frame(frame); t_frame.pack(side=TOP,expand=YES,fill=BOTH) self.text = Text(t_frame, wrap='word', setgrid=1 ) self.text.pack(side=LEFT, expand=YES, fill=BOTH ) vbar = Scrollbar(t_frame, command=self.text.yview ) vbar.pack(side=LEFT, fill=Y ) self.text['yscrollcommand'] = vbar.set self.text.insert(END, 'This window demonstrates how to use the tagging '+ 'facilities in text widgets to implement a searching ' 'mechanism. First, type a file name in the top '+ 'entry, then type <Return> or click on "Load File".'+ 'Then type a string in the lower entry and type '+ '<Return> or click on "Hilight". This will cause '+ 'all of the instances of the string to be tagged ' + 'with the tag "search", and it will arrange for the '+ 'tag\'s display attributes to change to make all '+ 'of the strings blink.' ) self.blink='stop' self.timer = None # set a callback on window closure to remove timer self.wm_protocol('WM_DELETE_WINDOW', self.close )
def __init__(self): DemoWindow.__init__(self, '', 'bind.py' ) frame = Frame(self); frame.pack(expand=Y, fill=BOTH ) text=Text(frame, relief=SUNKEN, bd=2, setgrid=1, wrap='word', height=35); text.pack(side=LEFT, expand=Y, fill=BOTH) bar=Scrollbar(frame); bar.pack(side=LEFT, fill=Y) text['yscrollcommand']=bar.set; bar['command']=text.yview self.text = text self.tags = range(0,6) # create and binds the tags for t in self.tags: self.text.tag_configure (t) self.text.tag_bind(t, '<Any-Enter>', callit(self.reconfigure_tag, t, 'bold' )) self.text.tag_bind(t, '<Any-Leave>', callit(self.reconfigure_tag, t, 'normal' )) self.text.tag_bind(t, '<1>', callit(self.link_callback, t )) # insert tagged text intro = """ The same tag mechanism that controls display styles in text widgets can also be used to associate Tcl commands with regions of text, so that mouse or keyboard actions on the text cause particular Tcl commands to be invoked. For example, in the text below the descriptions of the canvas demonstrations have been tagged. When you move the mouse over a demo description the description lights up, and when you press button 1 over a description then that particular demonstration is invoked. """ text.insert('0.0', intro ) text.insert( END, '1. Samples of all the different types of items that'+ ' can be created in canvas widgets.', self.tags[0] ) text.insert( END, '\n\n'); text.insert( END, '2. A simple two-dimensional plot that allows you '+ 'to adjust the positions of the data points.', self.tags[1] ) text.insert( END, '\n\n'); text.insert( END, '3. Anchoring and justification modes for text items.', self.tags[2] ) text.insert( END, '\n\n'); text.insert( END, '4. An editor for arrow-head shapes for line items.', self.tags[3] ) text.insert( END, '\n\n'); text.insert( END, '5. A ruler with facilities for editing tab stops.', self.tags[4] ) text.insert( END, '\n\n'); text.insert( END, '6. A grid that demonstrates how canvases can be '+ 'scrolled.', self.tags[5] )
def __init__(self ): l = """This window displays a canvas widget containing a simple 2-dimensional plot. You can doctor the data by dragging any of the points with mouse button 1.""" DemoWindow.__init__(self,l, 'canvasplot.py') self.canvas = CanvasPlot(self) self.canvas.pack(side=TOP)
def __init__(self): l = """This window displays a canvas widget containing a simple 2-dimensional plot. You can doctor the data by dragging any of the points with mouse button 1.""" DemoWindow.__init__(self, l, 'canvasplot.py') self.canvas = CanvasPlot(self) self.canvas.pack(side=TOP)
def __init__(self): l = """This canvas widget shows a mock-up of a ruler. You can create tab stops by dragging them out of the well to the right of the ruler. You can also drag existing tab stops. If you drag a tab stop far enough up or down so that it turns dim, it will be deleted when you release the mouse button.""" DemoWindow.__init__(self, l, demo_path('ruler.py')) self.canvas = RulerCanvas(self) self.canvas.pack(expand=YES, fill=BOTH )
def __init__(self): l = """This window displays a canvas widget that can be scrolled either using the scrollbars or by dragging with button 2 in the canvas. If you click button 1 on one of the rectangles, its indices will displayed. You can also drag with button 3 to scroll the canvas. """ DemoWindow.__init__(self,l,demo_path('canvasscroll.py') ) self.canvas = ScrollableCanvas(self) self.canvas.pack(expand='Y', fill='both' )
def __init__(self): l = """This window displays a canvas widget that can be scrolled either using the scrollbars or by dragging with button 2 in the canvas. If you click button 1 on one of the rectangles, its indices will displayed. You can also drag with button 3 to scroll the canvas. """ DemoWindow.__init__(self, l, demo_path('cscroll.py')) self.canvas = ScrollableCanvas(self) self.canvas.pack(expand='Y', fill='both')
def __init__(self): l = """This canvas widget shows a mock-up of a ruler. You can create tab stops by dragging them out of the well to the right of the ruler. You can also drag existing tab stops. If you drag a tab stop far enough up or down so that it turns dim, it will be deleted when you release the mouse button.""" DemoWindow.__init__(self, l, demo_path('canvasruler.py')) self.canvas = RulerCanvas(self) self.canvas.pack(expand=YES, fill=BOTH )
def __init__(self): l = """Press the buttons below to choose the foreground and background colors for the widgets in this window.""" DemoWindow.__init__(self, l, demo_path('clrpick.py')) frame = Frame(self) frame.pack(expand=YES, fill=BOTH) button_fg = Button(frame, text='Foreground', command=self.fg_callback) button_bg = Button(frame, text='Background', command=self.bg_callback) for b in button_fg, button_bg: b.pack(side=TOP, padx=10, pady=5, expand=YES, fill=X) self.all_widgets = (frame, button_fg, button_bg)
def __init__(self): l = ("""This window contains a menubar with cascaded menus. You can post a menu from the keyboard by typing %s+x, where \"x\" is the character underlined on the menu. You can then traverse among the menus using the arrow keys. When a menu is posted, you can invoke the current entry by typing space, or you can invoke any entry by typing its underlined character. If a menu entry has an accelerator, you can invoke the entry without posting the menu just by typing the accelerator. The rightmost menu can be torn off into a palette by selecting the first item in the menu. """ % POST_KEY ) DemoWindow.__init__(self,l, demo_path('menu.py'))
def __init__(self): l = ("""This window contains a menubar with cascaded menus. You can post a menu from the keyboard by typing %s+x, where \"x\" is the character underlined on the menu. You can then traverse among the menus using the arrow keys. When a menu is posted, you can invoke the current entry by typing space, or you can invoke any entry by typing its underlined character. If a menu entry has an accelerator, you can invoke the entry without posting the menu just by typing the accelerator. The rightmost menu can be torn off into a palette by selecting the first item in the menu. """ % POST_KEY) DemoWindow.__init__(self, l, demo_path('menu.py'))
def __init__(self): l="""A listbox containing the 50 states is displayed below, along with a scrollbar. You can scan the list either using the scrollbar or by scanning. To scan, press button 2 in the widget and drag up or down.""" DemoWindow.__init__(self, l, 'states.py' ) # create the list self.list=HScrollList(self) self.list.pack(expand=YES, fill=Y ) # scroll the list for i in StatesDemo.states: self.list.list.insert(END,i)
def __init__(self): l = """This widget allows you to experiment with different widths and arrowhead shapes for lines in canvases. To change the line width or the shape of the arrowhead, drag any of the three boxes attached to the oversized arrow. The arrows on the right give examples at normal scale. The text at the bottom shows the configuration options as you'd enter them for a canvas line item """ DemoWindow.__init__(self,l,'arrow.py' ) self.canvas = ArrowHeadCanvas(self, relief=SUNKEN, border=2, height=350, width=450) self.canvas.pack(side=TOP, expand=YES, fill=BOTH )
def __init__(self): l = """Press the buttons below to choose the foreground and background colors for the widgets in this window.""" DemoWindow.__init__(self,l,demo_path('clrpick.py')) frame=Frame(self); frame.pack(expand=YES, fill=BOTH) button_fg = Button(frame, text='Foreground', command=self.fg_callback ) button_bg = Button(frame, text='Background', command=self.bg_callback ) for b in button_fg,button_bg: b.pack(side=TOP, padx=10, pady=5, expand=YES, fill=X ) self.all_widgets = ( frame, button_fg, button_bg )
def __init__(self): l="""This demo shows you two ways of having a dialog to grab focus: local and global grab. Click on the relevant button and learn about the differences""" DemoWindow.__init__(self, l, demo_path('dialoggrab.py')) frame=Frame(self, relief=RIDGE,border=2); frame.pack(expand=YES,fill=BOTH) b1=Button(frame,text='Open dialog with local grab', command=self.localgrab_callback) b2=Button(frame,text='Open dialog with global grab', command=self.globalgrab_callback) for b in b1,b2: b.pack(side=LEFT, padx=5)
def __init__(self): l = """This widget allows you to experiment with different widths and arrowhead shapes for lines in canvases. To change the line width or the shape of the arrowhead, drag any of the three boxes attached to the oversized arrow. The arrows on the right give examples at normal scale. The text at the bottom shows the configuration options as you'd enter them for a canvas line item """ DemoWindow.__init__(self,l,'arrowhead.py' ) self.canvas = ArrowHeadCanvas(self, relief=SUNKEN, border=2, height=350, width=450) self.canvas.pack(side=TOP, expand=YES, fill=BOTH )
def __init__(self): l = """A listbox containing the 50 states is displayed below, along with a scrollbar. You can scan the list either using the scrollbar or by scanning. To scan, press button 2 in the widget and drag up or down.""" DemoWindow.__init__(self, l, 'states.py') # create the list self.list = HScrollList(self) self.list.pack(expand=YES, fill=Y) # scroll the list for i in StatesDemo.states: self.list.list.insert(END, i)
def __init__(self): l = """This window contains a canvas widget with examples of the various kinds of items supported by canvases. The following operations are supported: Button-1 drag: moves item under pointer. Button-2 drag: repositions view. Button-3 drag: strokes out area. Ctrl+f: prints items under area. """ DemoWindow.__init__(self,l, 'canvasitems.py' ) #create the canvas and the scroll bars frame = Frame(self); frame.pack(expand=YES, fill=BOTH ) self.canvas=DragCanvas(frame, scrollregion=(0,0,'30c','24c'), relief=SUNKEN, border=2,width='15c',height='10c' ) hbar = Scrollbar(frame, orient='horiz', command=self.canvas.xview) vbar=Scrollbar(frame, command=self.canvas.yview) self.canvas.configure({'xscrollcommand':hbar.set, 'yscrollcommand':vbar.set} ) frame.rowconfigure(0, weight=1 ) frame.columnconfigure(0, weight=1 ) self.canvas.grid(row=0,column=0, sticky='nsew') hbar.grid(row=1,column=0, sticky='ew') vbar.grid(row=0,column=1, sticky='ns' ) # create grid lines width, height = 30,24; unit='c' nrow, ncol = 3,2 dx, dy = width/ncol, height/nrow self.canvas.create_rectangle( 0, 0, `width`+unit, `height`+unit, width=2 ) for i in range(1,nrow): x1,y1,x2,y2 = 0,dy*i,width, dy*i self.canvas.create_line( `x1`+unit, `y1`+unit, `x2`+unit, `y2`+unit, width=2 ) for i in range(1,ncol): x1,y1,x2,y2 = dx*i,0,dx*i,height self.canvas.create_line( `x1`+unit, `y1`+unit, `x2`+unit, `y2`+unit, width=2 ) # this procedure is getting quite lengthy # better define sub-procedure to create the various items # the arguments define the canvas sub-area to use self.create_lines( 0, 0, dx, dy, unit ) self.canvas.set_draggable(self.canvas.gettags('item'))
def __init__(self): l="""This window contains a simple form where you can type in the various entries and use tabs to move circularly between the entries.""" DemoWindow.__init__(self, l, 'entry3.py') frame = Frame(self);frame.pack( expand=YES, fill=X) for text in ('Name:', 'Address:', '', '', 'Phone' ): f = Frame(frame, bd=2 ); f.pack(side=TOP, fill=X ) l = Label( f, text=text ); l.pack(side=LEFT) e = Entry(f, relief=SUNKEN, border=2, width=40 ); e.pack(side=RIGHT)
def __init__(self): l="""This window contains a simple form where you can type in the various entries and use tabs to move circularly between the entries.""" DemoWindow.__init__(self, l, 'form.py') frame = Frame(self);frame.pack( expand=YES, fill=X) for text in ('Name:', 'Address:', '', '', 'Phone' ): f = Frame(frame, bd=2 ); f.pack(side=TOP, fill=X ) l = Label( f, text=text ); l.pack(side=LEFT) e = Entry(f, relief=SUNKEN, border=2, width=40 ); e.pack(side=RIGHT)
def __init__(self): l = """This demo shows you two ways of having a dialog to grab focus: local and global grab. Click on the relevant button and learn about the differences""" DemoWindow.__init__(self, l, demo_path('dialoggrab.py')) frame = Frame(self, relief=RIDGE, border=2) frame.pack(expand=YES, fill=BOTH) b1 = Button(frame, text='Open dialog with local grab', command=self.localgrab_callback) b2 = Button(frame, text='Open dialog with global grab', command=self.globalgrab_callback) for b in b1, b2: b.pack(side=LEFT, padx=5)
def __init__(self): l="""A listbox containing several color names is displayed below, along with a scrollbar. You can scan the list either using the scrollbar or by dragging in the listbox window with button 2 pressed. If you double-click button 1 on a color, then the application's color palette will be set to match that color """ DemoWindow.__init__(self, l, 'states.py' ) # create the list self.list=HScrollList(self) self.list.pack(expand=YES, fill=Y ) self.list.list.bind('<Double-1>', self.callback ) # fill the list for i in colors: self.list.list.insert(END,i)
def __init__(self): l = """A listbox containing several color names is displayed below, along with a scrollbar. You can scan the list either using the scrollbar or by dragging in the listbox window with button 2 pressed. If you double-click button 1 on a color, then the application's color palette will be set to match that color """ DemoWindow.__init__(self, l, 'states.py') # create the list self.list = HScrollList(self) self.list.pack(expand=YES, fill=Y) self.list.list.bind('<Double-1>', self.callback) # fill the list for i in colors: self.list.list.insert(END, i)
def __init__(self): l = """ This window displays a string of text to demonstrate the text facilities of canvas widgets. You can click in the boxes to adjust the position of the text relative to its positioning point or change its justification. The text also supports the following simple bindings for editing: 1. You can point, click, and type. 2. You can also select with button 1. 3. You can copy the selection to the mouse position with button 2. 4. Backspace and Control+h delete the selection if there is one; otherwise they delete the character just before the insertion cursor. 5. Delete deletes the selection if there is one; otherwise it deletes the character just after the insertion cursor. """ DemoWindow.__init__(self, l, demo_path('ctext.py')) self.canvas = TextDemoCanvas(self) self.canvas.pack(fill=BOTH, expand=Y)
def __init__(self): l = """ This window displays a string of text to demonstrate the text facilities of canvas widgets. You can click in the boxes to adjust the position of the text relative to its positioning point or change its justification. The text also supports the following simple bindings for editing: 1. You can point, click, and type. 2. You can also select with button 1. 3. You can copy the selection to the mouse position with button 2. 4. Backspace and Control+h delete the selection if there is one; otherwise they delete the character just before the insertion cursor. 5. Delete deletes the selection if there is one; otherwise it deletes the character just after the insertion cursor. """ DemoWindow.__init__(self,l, demo_path('canvastext.py') ) self.canvas = TextDemoCanvas(self) self.canvas.pack(fill=BOTH, expand=Y)
def __init__(self): l = """An arrow and an horizontal scale are displayed below. If you click or drag mouse button 1 in the scale, you can change the size of the arrow.""" DemoWindow.__init__(self, l, demo_path('hscale.py')) self.frame = Frame(self,width=550,height=300) self.frame.pack(expand=Y,fill=BOTH) self.scale = Scale(self.frame, orient='horizontal', length=300, from_=0, to_=250, tickinterval=50, command=self.scale_callback ) self.scale.pack(side=TOP,expand=Y, fill=Y, padx=30) self.canvas = Canvas( self.frame, height=150, width=320 ) self.canvas.pack(side=LEFT,expand=Y, fill=BOTH ) options={'fill':'cyan', 'outline':'darkblue' } self.arrow = self.canvas.create_polygon( *self.arrow_points(50) ) self.canvas.itemconfigure( self.arrow, options ) self.scale.set(50)
def __init__(self): l = """Enter a file name in the entry box or click on the \"Browse\" buttons to select a file name using the file selection dialog.""" DemoWindow.__init__(self, l, demo_path('filebox.py')) frame = Frame(self) frame.pack(side=TOP, expand=YES, fill=BOTH) l1 = Label(frame, text='Select a file to open:') l2 = Label(frame, text='Select a file to save:') e1 = Entry(frame) self.e1 = e1 e2 = Entry(frame) self.e2 = e2 b1 = Button(frame, text='Browse...', command=self.selectopen_callback) b2 = Button(frame, text='Browse...', command=self.selectsave_callback) frame.rowconfigure(1, pad=10, weight=1) for r in (0, 1, 2): frame.columnconfigure(r, pad=5) # insert elements in the container rnum = 0 for r in ((l1, e1, b1), (l2, e2, b2)): cnum = 0 for w in r: w.grid(row=rnum, column=cnum) cnum = cnum + 1 rnum = rnum + 1 self.mvar = IntVar(self) mb = Checkbutton(self, text='Use motif stile dialog', variable=self.mvar, command=self.changestyle_callback) mb.pack(side=TOP, expand=YES, fill=X)
def __init__(self): l="""This window displays all of Tk's built-in bitmaps, along with the names you can use for them in scripts. """ DemoWindow.__init__(self,l, demo_path('builtinbitmaps.py')) frame=Frame(self);frame.pack(expand=YES, fill=BOTH, pady=10) list=( 'error', 'gray12', 'gray25', 'gray50', 'gray75', 'hourglass', 'info', 'question', 'questhead', 'warning' ) row=0; column=0 for b in list: f = Frame(frame) l1=Label(f, bitmap=b ); l1.pack(side=TOP) l2=Label(f, text=b);l2.pack(side=BOTTOM) f.grid(row=row, column=column, sticky='ns', padx=10 ) column=column+1; if column >= len(list)/2: row=row+1 column=0
def __init__(self): l = """This demonstration allows you to view images using a Tk "photo" image. First type a directory name in the text entry, then type Return to load the directory into the listbox. Then double-click on a file name in the listbox to see that image. """ DemoWindow.__init__(self,l,demo_path('image2.py')) frame=Frame(self);frame.pack(side=TOP,expand=YES,fill=BOTH) self.frame = frame #create the directory entry label_dir = Label(frame, text='Directory:') label_dir.pack(side=TOP, pady=5) self.entry_dir = Entry(frame) self.entry_dir.pack(side=TOP,expand=YES, fill=X ) # define the callback to call when user enters <return> in the entry self.entry_dir.bind('<Return>', self.entry_callback ) # create and pack the list of image files label_file = Label(frame, text='File:') label_file.pack(side=TOP, pady=10 ) self.list_file = HScrollList(frame) self.list_file.pack(side=TOP, expand=YES, fill=X) self.list_file.list.bind('<Double-1>', self.list_callback ) #create the label which contains the image and its title self.image_title = Label(frame, text='Image:') self.image_title.pack(side=TOP, pady=10 ) self.image_label = Label(frame) self.image_label.pack(side=TOP ) #pre-set interface to image subdirectory self.entry_dir.insert(0,'images') self.entry_callback()
def __init__(self): l = """This demonstration allows you to view images using a Tk "photo" image. First type a directory name in the text entry, then type Return to load the directory into the listbox. Then double-click on a file name in the listbox to see that image. """ DemoWindow.__init__(self,l,demo_path('imageif.py')) frame=Frame(self);frame.pack(side=TOP,expand=YES,fill=BOTH) self.frame = frame #create the directory entry label_dir = Label(frame, text='Directory:') label_dir.pack(side=TOP, pady=5) self.entry_dir = Entry(frame) self.entry_dir.pack(side=TOP,expand=YES, fill=X ) # define the callback to call when user enters <return> in the entry self.entry_dir.bind('<Return>', self.entry_callback ) # create and pack the list of image files label_file = Label(frame, text='File:') label_file.pack(side=TOP, pady=10 ) self.list_file = HScrollList(frame) self.list_file.pack(side=TOP, expand=YES, fill=X) self.list_file.list.bind('<Double-1>', self.list_callback ) #create the label which contains the image and its title self.image_title = Label(frame, text='Image:') self.image_title.pack(side=TOP, pady=10 ) self.image_label = Label(frame) self.image_label.pack(side=TOP ) #pre-set interface to image subdirectory self.entry_dir.insert(0,'images') self.entry_callback()
def __init__(self): l = """This is a demonstration of menubuttons. The \"Below\" menubutton pops its menu below the button; the \"Right\" button pops to the right, etc. There are two option menus directly below this text; one is just a standard menu and the other is a 16-color palette. """ DemoWindow.__init__(self, l, demo_path('menubu.py')) frame = Frame(self) frame.pack(expand=YES, fill=BOTH) frame.rowconfigure(1, weight=1, pad=120) frame.columnconfigure(1, weight=1, pad=120) #create the 'number' option menu in the middle middleframe = Frame(frame) middleframe.grid(row=1, column=1) var_numbers = StringVar(middleframe) var_numbers.set('One') om_numbers = OptionMenu(middleframe, var_numbers, 'One', 'Two', 'Three') om_numbers.pack(side=LEFT, padx=10) #create the 'color' optionmenu in the middle colors = ('Black', 'red4', 'DarkGreen', 'NavyBlue', 'gray75', 'Red', 'Green', 'Blue', 'gray50', 'Yellow', 'Cyan', 'Magenta', 'White', 'Brown', 'DarkSeaGreen', 'DarkViolet') var_colors = StringVar(middleframe) var_colors.set(colors[0]) var_colors.trace_variable('w', self.colorsupdate_callback) om_colors = apply(OptionMenu, (middleframe, var_colors) + colors) om_colors['menu'].entryconfigure(len(colors) / 3, columnbreak=1) om_colors['menu'].entryconfigure(2 * len(colors) / 3 + 1, columnbreak=1) om_colors.pack(side=RIGHT, padx=10) print(om_colors) print(om_colors['menu']) # set images for color menu options self.images = [] for i in range(0, len(colors)): img = PhotoImage(name='image_' + colors[i], height=16, width=16) self.images.append(img) # images shall live as long as the menu img.put(colors[i], to=(0, 0, 15, 15)) om_colors['menu'].entryconfigure(i, image=img) # for some reason, if this is done before the above loop, # the menu entries lose the 'image' property # Also the tk demo does this at the end om_colors['menu'].configure(tearoff=1) # store vars needed for callbacks self.var_colors = var_colors self.om_colors = om_colors #create the four menu buttons at the edge of the frame for text, direction, row, column, sticky in (('Above', 'above', 2, 1, 's'), ('Below', 'below', 0, 1, 'n'), ('Left', 'left', 1, 0, 'w'), ('Right', 'right', 1, 2, 'e')): mb = Menubutton(frame, text=text, underline=0, relief=RAISED, direction=direction) menu = Menu(mb, tearoff=0) mb['menu'] = menu menu.add_command(label=text + ' menu first option', underline=len(text) + 1) menu.add_command(label=text + ' menu second option', underline=len(text) + 1) mb.grid(row=row, column=column, sticky=sticky)
def __init__(self): DemoWindow.__init__(self, '', 'taggedtext.py' ) frame = Frame(self); frame.pack(expand=Y, fill=BOTH ) text=Text(frame, relief=SUNKEN, bd=2, setgrid=1, height=35, wrap='word'); text.pack(side=LEFT, expand=Y, fill=BOTH) bar=Scrollbar(frame); bar.pack(side=LEFT, fill=Y) text['yscrollcommand']=bar.set; bar['command']=text.yview # create the tags bold = TextTag(text,font='Courier 12 bold italic') big = TextTag(text, font='Courier 14 bold') verybig = TextTag(text, font='Helvetica 24 bold') if self.winfo_depth > 1 : color1 = TextTag(text, background='#a0b7ce') color2 = TextTag(text, foreground='red') raised = TextTag(text, relief='raised', borderwidth=1 ) sunken = TextTag(text, relief='sunken', borderwidth=1 ) else: color1 = TextTag(text, background='black', foreground='2hite') color2 = TextTag(text, background='black', foreground='white') raised = TextTag(text, background='white', relief='raised', borderwidth=1 ) sunken = TextTag(text, background='white', relief='sunken', borderwidth=1 ) bgstipple = TextTag(text, background='black', borderwidth=0, bgstipple='gray12' ) fgstipple = TextTag(text, fgstipple='gray50') underline = TextTag(text, underline='on') overstrike = TextTag(text, overstrike='on') right=TextTag(text, justify='right') center=TextTag(text, justify='center') super = TextTag(text, offset='4p', font='Courier 10') sub = TextTag(text, offset='-2p', font='Courier 10') margins = TextTag(text, lmargin1='12m', lmargin2='6m', rmargin='10m' ) spacing = TextTag(text, spacing1='10p', spacing2='2p', lmargin1='12m', lmargin2='6m', rmargin='10m') # insert tagged text tagged_text = ( ( 'Text widgets like this one allow you to display information'+ ' in a variety of styles. Display styles are controlled using' + ' a mechanism called ', None ), ( 'tags', bold.id ), ( '\n Tags are just textual names that you can apply to one '+ 'or more ranges of characters within a text widget. You can '+ 'configure tags with various display styles. If you do this,'+ ' then the tagged characters will be displayed with the styles '+ 'you chose. \nThe available display styles are:', None ), ( '\n1. Font.', big.id ), ( ' You can choose any X font, ', None ), ( 'large', verybig.id ), ( ' or ', None ), ( 'small.\n', None ), ( '\n2. Color.', big.id ), ( ' You can change either the ', None ), ( 'background', color1.id ), ( ' or ', None ), ( 'foreground', color2.id ), ( ' or ', None ), ( 'both.\n', (color1.id, color2.id ) ), ( '\n3. Stippling.', big.id ), ( ' You can cause either the ', None ), ( 'background ', bgstipple.id ), ( ' or ', None ), ( 'foreground', fgstipple.id ), ( ' information to be drawn with a stipple instead of a solid fill. \n', None ), ( '\n4. Underlining.', big.id ), ( ' You can ', None ), ( 'underline', underline.id ), ( ' ranges of text. \n', None ), ( '\n5. Overstrikes.', big.id ), ( ' You can ', None ), ( 'draw lines through', overstrike.id ), ( ' ranges of text.\n', None ), ( '\n6. 3-D effects.', big.id ), ( ' You can arrange for the background to be drawn with a '+ 'border that makes characters appear either ', None ), ( 'raised', raised.id ), ( ' or ', None ), ( 'sunken', sunken.id ), ( '\n', None ), ( '\n7. Justification.', big.id ), ( ' You can arrange for lines to be displayed\n', None ), ( 'left-justified,\n', None ), ( 'right-justified, or\n', right.id ), ( 'centerer.\n', center.id ), ( '\n8. Superscripts and subscripts.', big.id ), ( ' You can control the vertical position to generate '+ 'superscript effects like 10', None ), ( 'n', super.id ), ( ' or subscript effects like X', None ), ( 'i', sub.id ), ( '.\n', None ), ( '\n9. Margins.', big.id ), ( ' You can control the amount of extra space left on '+ 'each side of the text:\n', None ), ( 'This paragraph is an example of the use of '+ 'margins. It consists of a single line of text '+ 'that wraps around the screen. There are two '+ 'separate left margins values, one for the first '+ 'display line associated with the text line, ' + 'and one for the subsequent display lines, which '+ 'occur because of wrapping. There is also a '+ 'separate specification for the right margin, which '+ 'is used to choose wrap points for lines. \n', margins.id ), ( '\n10. Spacing.', big.id ), ( 'You can control the spacing of lines with three '+ 'separate parameters. "Spacing1" tells how much '+ 'extra space to leave above a line, '+ '"spacing 3" tells how much space to leave below a line'+ ' and if a line wraps, "spacing2" tells how much space to leave'+ ' between the display lines that make up the text line.\n', None ), ( 'These indented paragraphs illustrates how spacing '+ 'can be used. Each pharagraph is actually a '+ 'single line in the text widget, which is '+ 'word-wrapped by the widget.\n', spacing.id ), ( 'Spacing1 is set to 10 points for this text, '+ 'which results in relatively large gaps between '+ 'the paragraphs. Spacing2 is set to 2 points, '+ 'which results in just a bit of extra space within a '+ 'paragraph. Spacing3 isn\'t used in this example.', spacing.id ), ( '\nTo see where the space is, select ranges of text '+ 'within these paragraphs. The selection hilight will cover'+ ' the extra space.', spacing.id ) ) for txt, tags in tagged_text: text.insert(END, txt, tags )
def __init__(self): DemoWindow.__init__(self, '', demo_path('twind.py') ) frame = Frame(self); frame.pack(expand=Y, fill=BOTH ) self.frame=frame frame.rowconfigure(0, weight=1 ) frame.columnconfigure(0, weight=1 ) self.text=Text(frame, relief=SUNKEN, bd=2, setgrid=1, wrap='word', height=35); self.text.grid(row=0,column=0, sticky='nsew') bar=Scrollbar(frame); bar.grid(row=0,column=1,sticky='nsew') self.text['yscrollcommand']=bar.set; bar['command']=self.text.yview self.hscroll = None # preset is needed because it is checked in the self.plot = None # callbacks #these are the buttons which will be embedded in the text self.b_turnon = Button(self.text, text='Turn On', cursor='top_left_arrow', command = self.turnon_callback ) self.b_turnoff = Button( self.text, text='Turn Off', cursor='top_left_arrow', command=self.turnoff_callback ) self.b_clickhere = Button(self.text, text='Click Here', cursor='top_left_arrow', command=self.clickhere_callback ) self.b_delete = Button( self.text,text='Delete', cursor='top_left_arrow', command=self.delete_callback ) # insert text and embedding buttons self.text.insert(END, "A text widget can contain other widgets embedded "+ "in it. These are called \"embedded windows\", "+ "and they can consist of arbitrary widgets. "+ "For example, here are two embedded button "+ "widgets. You can click on the first button to " ) self.text.window_create(END, window=self.b_turnon ) self.text.insert(END, " horizontal scrolling, which also turns off "+ "word wrapping. Or, you can click on the second "+ "button to " ) self.text.window_create(END, window=self.b_turnoff ) self.text.insert(END, "horizontal scrolling and turn back on word wrapping.\n\n" ) self.text.insert(END, "Or, here is another example. If you ") self.text.window_create(END, window=self.b_clickhere ) self.text.insert(END, "a canvas displaying an x-y plot will appear right "+ "here." ) # insert a mark where the plot window shall be inserted self.text.mark_set('plot', INSERT ) self.text.mark_gravity('plot', LEFT) self.text.insert(END, "\nYou can drag the data points around with "+ "the mouse, or you can click here to ") self.text.window_create(END, window=self.b_delete ) self.text.insert(END, " the plot again.\n\n") self.text.insert( END, "You may also find it useful to put embedded windows in " "a text without any actual text. In this case the "+ "text widget acts like a geometry manager. For "+ "example, here is a collection of buttons laid out "+ "neatly into rows by the text widget. These buttons "+ "can be used to change the background color of the "+ "text widget (\"Default\" restores the color to "+ "its default). If you click on the button labeled "+ "\"Short\", it changes to a longer string so that "+ "you can see how the text widget automatically "+ "changes the layout. Click on the button again "+ "to restore the short string.\n" ) self.var = StringVar(self.text) self.var.set('Short') tb = Checkbutton( self.text, indicatoron=0, textvariable=self.var, variable=self.var, offvalue='Short', onvalue='A much longer string', cursor='top_left_arrow', padx=2, pady=4) self.text.window_create(END, window=tb ) colors = ( 'AntiqueWhite3', 'Bisque1', 'Bisque2', 'Bisque3', 'Bisque4', 'SlateBlue3', 'RoyalBlue1', 'SteelBlue2', 'DeepSkyBlue3', 'LightBlue1', 'DarkSlateGray1', 'Aquamarine2', 'DarkSeaGreen2', 'SeaGreen1', 'Yellow1', 'IndianRed1', 'IndianRed2', 'Tan1', 'Tan4' ) c = self.text['background'] db = Button(self.text, text='Default', background=c, command=callit(self.button_callback, c ), cursor = 'top_left_arrow' ) self.text.window_create(END, window=db) for c in colors: b = Button(self.text, text=c, background=c, padx=2, pady=4, cursor='top_left_arrow', command=callit(self.button_callback, c )) self.text.window_create(END, window=b)
def __init__(self): DemoWindow.__init__(self, '', 'style.py') frame = Frame(self) frame.pack(expand=Y, fill=BOTH) text = Text(frame, relief=SUNKEN, bd=2, setgrid=1, height=35, wrap='word') text.pack(side=LEFT, expand=Y, fill=BOTH) bar = Scrollbar(frame) bar.pack(side=LEFT, fill=Y) text['yscrollcommand'] = bar.set bar['command'] = text.yview # create the tags bold = TextTag(text, font='Courier 12 bold italic') big = TextTag(text, font='Courier 14 bold') verybig = TextTag(text, font='Helvetica 24 bold') if self.winfo_depth() > 1: color1 = TextTag(text, background='#a0b7ce') color2 = TextTag(text, foreground='red') raised = TextTag(text, relief='raised', borderwidth=1) sunken = TextTag(text, relief='sunken', borderwidth=1) else: color1 = TextTag(text, background='black', foreground='2hite') color2 = TextTag(text, background='black', foreground='white') raised = TextTag(text, background='white', relief='raised', borderwidth=1) sunken = TextTag(text, background='white', relief='sunken', borderwidth=1) bgstipple = TextTag(text, background='black', borderwidth=0, bgstipple='gray12') fgstipple = TextTag(text, fgstipple='gray50') underline = TextTag(text, underline='on') overstrike = TextTag(text, overstrike='on') right = TextTag(text, justify='right') center = TextTag(text, justify='center') super = TextTag(text, offset='4p', font='Courier 10') sub = TextTag(text, offset='-2p', font='Courier 10') margins = TextTag(text, lmargin1='12m', lmargin2='6m', rmargin='10m') spacing = TextTag(text, spacing1='10p', spacing2='2p', lmargin1='12m', lmargin2='6m', rmargin='10m') # insert tagged text tagged_text = ( ('Text widgets like this one allow you to display information' + ' in a variety of styles. Display styles are controlled using' + ' a mechanism called ', None), ('tags', bold.id), ('\n Tags are just textual names that you can apply to one ' + 'or more ranges of characters within a text widget. You can ' + 'configure tags with various display styles. If you do this,' + ' then the tagged characters will be displayed with the styles ' + 'you chose. \nThe available display styles are:', None), ('\n1. Font.', big.id), (' You can choose any X font, ', None), ('large', verybig.id), (' or ', None), ('small.\n', None), ('\n2. Color.', big.id), (' You can change either the ', None), ('background', color1.id), (' or ', None), ('foreground', color2.id), (' or ', None), ('both.\n', (color1.id, color2.id)), ('\n3. Stippling.', big.id), (' You can cause either the ', None), ('background ', bgstipple.id), (' or ', None), ('foreground', fgstipple.id), (' information to be drawn with a stipple instead of a solid fill. \n', None), ('\n4. Underlining.', big.id), (' You can ', None), ('underline', underline.id), (' ranges of text. \n', None), ('\n5. Overstrikes.', big.id), (' You can ', None), ('draw lines through', overstrike.id), (' ranges of text.\n', None), ('\n6. 3-D effects.', big.id), (' You can arrange for the background to be drawn with a ' + 'border that makes characters appear either ', None), ('raised', raised.id), (' or ', None), ('sunken', sunken.id), ('\n', None), ('\n7. Justification.', big.id), (' You can arrange for lines to be displayed\n', None), ('left-justified,\n', None), ('right-justified, or\n', right.id), ('centerer.\n', center.id), ('\n8. Superscripts and subscripts.', big.id), (' You can control the vertical position to generate ' + 'superscript effects like 10', None), ('n', super.id), (' or subscript effects like X', None), ('i', sub.id), ('.\n', None), ('\n9. Margins.', big.id), (' You can control the amount of extra space left on ' + 'each side of the text:\n', None), ('This paragraph is an example of the use of ' + 'margins. It consists of a single line of text ' + 'that wraps around the screen. There are two ' + 'separate left margins values, one for the first ' + 'display line associated with the text line, ' + 'and one for the subsequent display lines, which ' + 'occur because of wrapping. There is also a ' + 'separate specification for the right margin, which ' + 'is used to choose wrap points for lines. \n', margins.id), ('\n10. Spacing.', big.id), ('You can control the spacing of lines with three ' + 'separate parameters. "Spacing1" tells how much ' + 'extra space to leave above a line, ' + '"spacing 3" tells how much space to leave below a line' + ' and if a line wraps, "spacing2" tells how much space to leave' + ' between the display lines that make up the text line.\n', None), ('These indented paragraphs illustrates how spacing ' + 'can be used. Each pharagraph is actually a ' + 'single line in the text widget, which is ' + 'word-wrapped by the widget.\n', spacing.id), ('Spacing1 is set to 10 points for this text, ' + 'which results in relatively large gaps between ' + 'the paragraphs. Spacing2 is set to 2 points, ' + 'which results in just a bit of extra space within a ' + 'paragraph. Spacing3 isn\'t used in this example.', spacing.id), ('\nTo see where the space is, select ranges of text ' + 'within these paragraphs. The selection hilight will cover' + ' the extra space.', spacing.id)) for txt, tags in tagged_text: text.insert(END, txt, tags)
def __init__(self): l = """This window contains a canvas widget with examples of the various kinds of items supported by canvases. The following operations are supported: Button-1 drag: moves item under pointer. Button-2 drag: repositions view. Button-3 drag: strokes out area. Ctrl+f: prints items under area. """ DemoWindow.__init__(self, l, 'items.py') #create the canvas and the scroll bars frame = Frame(self) frame.pack(expand=YES, fill=BOTH) self.canvas = DragCanvas(frame, scrollregion=(0, 0, '30c', '24c'), relief=SUNKEN, border=2, width='15c', height='10c') hbar = Scrollbar(frame, orient='horiz', command=self.canvas.xview) vbar = Scrollbar(frame, command=self.canvas.yview) self.canvas.configure({ 'xscrollcommand': hbar.set, 'yscrollcommand': vbar.set }) frame.rowconfigure(0, weight=1) frame.columnconfigure(0, weight=1) self.canvas.grid(row=0, column=0, sticky='nsew') hbar.grid(row=1, column=0, sticky='ew') vbar.grid(row=0, column=1, sticky='ns') # create grid lines width, height = 30, 24 unit = 'c' nrow, ncol = 3, 2 dx, dy = width / ncol, height / nrow self.canvas.create_rectangle(0, 0, 'width' + unit, 'height' + unit, width=2) for i in range(1, nrow): x1, y1, x2, y2 = 0, dy * i, width, dy * i self.canvas.create_line('x1' + unit, 'y1' + unit, 'x2' + unit, 'y2' + unit, width=2) for i in range(1, ncol): x1, y1, x2, y2 = dx * i, 0, dx * i, height self.canvas.create_line('x1' + unit, 'y1' + unit, 'x2' + unit, 'y2' + unit, width=2) # this procedure is getting quite lengthy # better define sub-procedure to create the various items # the arguments define the canvas sub-area to use self.create_lines(0, 0, dx, dy, unit) self.canvas.set_draggable(self.canvas.gettags('item'))
def __init__(self): DemoWindow.__init__(self, '', 'search.py') frame = Frame(self) frame.pack(expand=Y, fill=BOTH) # create the controls panel c_frame = Frame(frame) c_frame.pack(side=TOP, expand=Y, fill=X) c_frame.columnconfigure(1, weight=1, minsize=300) file_l = Label(c_frame, text='File name:') file_l.grid(row=0, column=0, sticky='w') self.filevar = StringVar(c_frame) self.file_e = Entry(c_frame, textvariable=self.filevar) self.file_e.grid(row=0, column=1, sticky='ew') self.file_e.bind('<Return>', self.load_callback) self.load_b = Button(c_frame, text='Load file', padx=10, command=self.load_callback) self.load_b.grid(row=0, column=2, sticky='e') string_l = Label(c_frame, text='Search string:') string_l.grid(row=1, column=0) self.stringvar = StringVar(c_frame) self.string_e = Entry(c_frame, textvariable=self.stringvar) self.string_e.grid(row=1, column=1, sticky='ew') self.string_e.bind('<Return>', self.hilight_callback) self.hilight_b = Button(c_frame, text='Hilight', padx=10, command=self.hilight_callback) self.hilight_b.grid(row=1, column=2) # create the text widget and related scrollbar t_frame = Frame(frame) t_frame.pack(side=TOP, expand=YES, fill=BOTH) self.text = Text(t_frame, wrap='word', setgrid=1) self.text.pack(side=LEFT, expand=YES, fill=BOTH) vbar = Scrollbar(t_frame, command=self.text.yview) vbar.pack(side=LEFT, fill=Y) self.text['yscrollcommand'] = vbar.set self.text.insert( END, 'This window demonstrates how to use the tagging ' + 'facilities in text widgets to implement a searching ' 'mechanism. First, type a file name in the top ' + 'entry, then type <Return> or click on "Load File".' + 'Then type a string in the lower entry and type ' + '<Return> or click on "Hilight". This will cause ' + 'all of the instances of the string to be tagged ' + 'with the tag "search", and it will arrange for the ' + 'tag\'s display attributes to change to make all ' + 'of the strings blink.') self.blink = 'stop' self.timer = None # set a callback on window closure to remove timer self.wm_protocol('WM_DELETE_WINDOW', self.close)
def __init__(self): DemoWindow.__init__(self, '', demo_path('twind.py')) frame = Frame(self) frame.pack(expand=Y, fill=BOTH) self.frame = frame frame.rowconfigure(0, weight=1) frame.columnconfigure(0, weight=1) self.text = Text(frame, relief=SUNKEN, bd=2, setgrid=1, wrap='word', height=35) self.text.grid(row=0, column=0, sticky='nsew') bar = Scrollbar(frame) bar.grid(row=0, column=1, sticky='nsew') self.text['yscrollcommand'] = bar.set bar['command'] = self.text.yview self.hscroll = None # preset is needed because it is checked in the self.plot = None # callbacks #these are the buttons which will be embedded in the text self.b_turnon = Button(self.text, text='Turn On', cursor='top_left_arrow', command=self.turnon_callback) self.b_turnoff = Button(self.text, text='Turn Off', cursor='top_left_arrow', command=self.turnoff_callback) self.b_clickhere = Button(self.text, text='Click Here', cursor='top_left_arrow', command=self.clickhere_callback) self.b_delete = Button(self.text, text='Delete', cursor='top_left_arrow', command=self.delete_callback) # insert text and embedding buttons self.text.insert( END, "A text widget can contain other widgets embedded " + "in it. These are called \"embedded windows\", " + "and they can consist of arbitrary widgets. " + "For example, here are two embedded button " + "widgets. You can click on the first button to ") self.text.window_create(END, window=self.b_turnon) self.text.insert( END, " horizontal scrolling, which also turns off " + "word wrapping. Or, you can click on the second " + "button to ") self.text.window_create(END, window=self.b_turnoff) self.text.insert( END, "horizontal scrolling and turn back on word wrapping.\n\n") self.text.insert(END, "Or, here is another example. If you ") self.text.window_create(END, window=self.b_clickhere) self.text.insert( END, "a canvas displaying an x-y plot will appear right " + "here.") # insert a mark where the plot window shall be inserted self.text.mark_set('plot', INSERT) self.text.mark_gravity('plot', LEFT) self.text.insert( END, "\nYou can drag the data points around with " + "the mouse, or you can click here to ") self.text.window_create(END, window=self.b_delete) self.text.insert(END, " the plot again.\n\n") self.text.insert( END, "You may also find it useful to put embedded windows in " "a text without any actual text. In this case the " + "text widget acts like a geometry manager. For " + "example, here is a collection of buttons laid out " + "neatly into rows by the text widget. These buttons " + "can be used to change the background color of the " + "text widget (\"Default\" restores the color to " + "its default). If you click on the button labeled " + "\"Short\", it changes to a longer string so that " + "you can see how the text widget automatically " + "changes the layout. Click on the button again " + "to restore the short string.\n") self.var = StringVar(self.text) self.var.set('Short') tb = Checkbutton(self.text, indicatoron=0, textvariable=self.var, variable=self.var, offvalue='Short', onvalue='A much longer string', cursor='top_left_arrow', padx=2, pady=4) self.text.window_create(END, window=tb) colors = ('AntiqueWhite3', 'Bisque1', 'Bisque2', 'Bisque3', 'Bisque4', 'SlateBlue3', 'RoyalBlue1', 'SteelBlue2', 'DeepSkyBlue3', 'LightBlue1', 'DarkSlateGray1', 'Aquamarine2', 'DarkSeaGreen2', 'SeaGreen1', 'Yellow1', 'IndianRed1', 'IndianRed2', 'Tan1', 'Tan4') c = self.text['background'] db = Button(self.text, text='Default', background=c, command=callit(self.button_callback, c), cursor='top_left_arrow') self.text.window_create(END, window=db) for c in colors: b = Button(self.text, text=c, background=c, padx=2, pady=4, cursor='top_left_arrow', command=callit(self.button_callback, c)) self.text.window_create(END, window=b)
def __init__(self): l = """This is a demonstration of menubuttons. The \"Below\" menubutton pops its menu below the button; the \"Right\" button pops to the right, etc. There are two option menus directly below this text; one is just a standard menu and the other is a 16-color palette. """ DemoWindow.__init__(self,l,demo_path('menubuttons.py')) frame= Frame(self);frame.pack( expand=YES, fill=BOTH ) frame.rowconfigure(1,weight=1, pad=120) frame.columnconfigure(1,weight=1,pad=120) #create the 'number' option menu in the middle middleframe = Frame(frame);middleframe.grid(row=1,column=1) var_numbers=StringVar(middleframe);var_numbers.set('One') om_numbers= OptionMenu(middleframe,var_numbers, 'One', 'Two', 'Three') om_numbers.pack(side=LEFT, padx=10) #create the 'color' optionmenu in the middle colors = ('Black', 'red4', 'DarkGreen', 'NavyBlue', 'gray75', 'Red', 'Green', 'Blue', 'gray50', 'Yellow', 'Cyan', 'Magenta', 'White', 'Brown', 'DarkSeaGreen', 'DarkViolet' ) var_colors=StringVar(middleframe);var_colors.set(colors[0]) var_colors.trace_variable('w', self.colorsupdate_callback ) om_colors=apply( OptionMenu, (middleframe,var_colors)+colors ) om_colors['menu'].entryconfigure(len(colors)/3, columnbreak=1) om_colors['menu'].entryconfigure(2*len(colors)/3+1, columnbreak=1) om_colors.pack(side=RIGHT,padx=10) print `om_colors` print `om_colors['menu']` # set images for color menu options self.images=[] for i in range(0,len(colors)): img = PhotoImage(name='image_'+colors[i], height=16,width=16) self.images.append(img) # images shall live as long as the menu img.put(colors[i], to=(0,0,15,15)) om_colors['menu'].entryconfigure(i, image=img ) # for some reason, if this is done before the above loop, # the menu entries lose the 'image' property # Also the tk demo does this at the end om_colors['menu'].configure(tearoff=1) # store vars needed for callbacks self.var_colors=var_colors self.om_colors=om_colors #create the four menu buttons at the edge of the frame for text,direction,row,column,sticky in ( ('Above','above',2,1,'s'), ('Below','below',0,1,'n'), ('Left','left',1,0,'w'), ('Right','right',1,2,'e')): mb=Menubutton(frame, text=text, underline=0, relief=RAISED, direction=direction ) menu = Menu(mb, tearoff=0) mb['menu']= menu menu.add_command(label=text+' menu first option', underline=len(text)+1) menu.add_command(label=text+ ' menu second option', underline=len(text)+1) mb.grid(row=row,column=column,sticky=sticky)