Example: biology

Tkinter reference: A GUI for Python

Tkinter reference: A GUI forPythonContentsPart I: The face of your application.. 31. A minimal application.. 32. Layout management.. ()method.. Other grid management methods .. 53. Standard attributes .. Dimensions.. Coordinate system.. Colors .. Fonts.. Bitmaps .. Cursors.. Images .. 94. TheButtonwidget .. 105. TheCanvaswidget .. The canvas arc object.. The canvas bitmap object .. The canvas image object .. The canvas line object .. The canvas oval object .. The canvas polygon object .. The canvas rectangle object .. The canvas text object .. The canvas window object .. 226. TheCheckbuttonwidget .. 237. TheEntrywidget.. Scrolling anEntrywidget .. 288. TheFramewidget.. 289.

widgets have a.grid()method that you can use to tell the geometry manager where to put it. 2.1 The.grid()method w.grid ( *options ) This method registers a widget w with the Gridgeometry manager—if you don’t do this, the widget will exist but it will not be visible on the screen. Here are the options to the.grid()geometry management method:

Tags:

  Geometry, Tkinter

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Tkinter reference: A GUI for Python

1 Tkinter reference: A GUI forPythonContentsPart I: The face of your application.. 31. A minimal application.. 32. Layout management.. ()method.. Other grid management methods .. 53. Standard attributes .. Dimensions.. Coordinate system.. Colors .. Fonts.. Bitmaps .. Cursors.. Images .. 94. TheButtonwidget .. 105. TheCanvaswidget .. The canvas arc object.. The canvas bitmap object .. The canvas image object .. The canvas line object .. The canvas oval object .. The canvas polygon object .. The canvas rectangle object .. The canvas text object .. The canvas window object .. 226. TheCheckbuttonwidget .. 237. TheEntrywidget.. Scrolling anEntrywidget .. 288. TheFramewidget.. 289.

2 TheLabelwidget.. 2910. TheListboxwidget .. Scrolling aListboxwidget .. 3411. TheMenuwidget.. 3412. TheMenubuttonwidget .. 3813. TheRadiobuttonwidget.. 4014. TheScalewidget .. 4315. TheScrollbarwidget .. The scrollbar command callback .. Connecting scrollbars to other widgets.. 4916. TheTextwidget.. Indices in text widgets.. 50 New Mexico Tech Computer CenterTkinter reference: A GUI for PythonPage Marks in text widgets .. Images in text widgets.. Windows in text widgets.. Tags in text widgets.. Methods on text widgets.. : Top-level window methods .. 6018. Universal widget methods.. 6119. Standardizing appearance and the option database.. How to name a widget class .. How to name a widget instance.. Resource specification lines .. Rules for resource matching.

3 72 Part II: Connecting the interface to the rest of your program.. 7320. Control variables: the values behind the widgets.. 7321. Focus: routing keyboard input.. 7522. Events: responding to stimuli .. Levels of binding .. Event sequences .. Event types .. Event modifiers.. Key names.. Writing an event handler.. The extra arguments trick .. Virtual events .. 84 Tkinter is a GUI widget set for Python . This document contains only the commonerfeatures. For complete documentation, see: the bookPython and Tkinter Programmingby John Grayson (Manning, 2000, ISBN1-884777-81-3).This document applies to Python and Tkinter running in the X Window systemunder Linux. Your version may to the author s companion publication, Python language quick reference, or to , for general information about the Python Mexico Tech Computer CenterTkinter reference: A GUI for PythonPage 2 Part I: The face of your applicationWe ll start by looking at the visible part of Tkinter : creating the widgets and arrangingthem on the screen.

4 In Part II, below, we will talk about how to connect the face the front panel of the application to the logic behind A minimal applicationHere is a trivial Tkinter program containing only a Quit button:#!/usr/local/bin/pythonfrom Tkinter import * # Interface to Tk widgetsclass Application(Frame):def __init__(self, master=None) (self, master) () ()def createWidgets(self) = Button ( self, text="Quit",command= ) ()app = Application() # Instantiate the application ("Sample application") () # Wait for events2. Layout managementLater we will discuss the widgets, the building blocks of your GUI application. How dowidgets get arranged in a window?Although there are three different geometry managers in Tkinter , the author stronglyprefers theGridgeometry manager for pretty much everything.

5 This manager treatsevery window or frame as a table a gridwork of rows and columns. Acellis the area at the intersection of one row and one column. The width of each column is the width of the widest cell in that column. The height of each row is the height of the largest cell in that row. For widgets that do not fill the entire cell, you can specify what happens to the extraspace. You can either leave the extra space outside the widget, or stretch the widgetto fit it, in either the horizontal or vertical dimension. You can combine multiple cells into one larger area, a process Mexico Tech Computer CenterTkinter reference: Layout managementPage 3 When you create a widget, it does not appear until you register it with a geometrymanager. Hence, construction and placing of a widget is a two-step process that goessomething like this:thing = Constructor(master.)

6 (..)whereConstructoris one of the widget classes likeButton,Frame, and so on. Allwidgets have ()method that you can use to tell the geometry manager where toput () ( *options )This method registers a widgetwwith theGridgeometry manager if you don t do this,the widget will exist but it will not be visible on the are the options to () geometry management method:columnThe column number where you want the widgetgridded, counting from zero. The default value a widget occupies only one cell in , you can grab multiple cells ofa row and merge them into one larger cell bysetting thecolumnspanoption to the number ofcells. For example, (row=0, column=2,columnspan=3)would place widgetwin a cellthat spans columns 2, 3, and 4 of row This dimension is added insidethe widget inside its left and right This dimension is added insidethe widget inside its top and bottom This dimension is added to theleft and right outside the This dimension is added aboveand below the row number into which you want to insert thewidget, counting from 0.

7 The default is the nexthigher-numbered unoccupied a widget occupies only one cell in thegrid. You can grab multiple adjacent cells of a col-umn, however, by setting therowspanoption to thenumber of cells to grab. This option can be used incombination with thecolumnspanoption to graba block of example, (row=3,column=2, rowspan=4, columnspan=5)wouldplace widgetwin an area formed by merging 20cells, with row numbers 3 6 and column numbers2 option determines how to distribute any extraspace within the cell that is not taken up by the wid-get at its natural size. See below for a Mexico Tech Computer CenterTkinter reference: Layout managementPage 4 If you do not provide astickyattribute, the default behavior is to center the widgetin the cell. You can position the widget in a corner of the cell by settingstickytoNE(top right),SE(bottom right),SW(bottom left), orNW(top left).

8 You can position the widget against one side of the cell by settingstickytoN(topcenter),E(right center),S(bottom center), orW(left center). SetstickytoN+Sto stretch the widget vertically but leave it centered horizontally. SetstickytoE+Wto stretch it horizontally but leave it centered vertically. Setsticky=N+E+S+Wto stretch the widget both horizontally and vertically to fillthe Other grid management ()This method makes widgetwdisappear from the screen. It still exists, it just isn t ()it to make it appear again, but it won t remember its grid ()Normally, all widgets propagate their dimensions, meaning that they adjust to fit thecontents. However, sometimes you want to force a widget to be a certain size, regardlessof the size of its contents. To do this, (0)wherewis the widgetwhose size you want to ()This method is (), but its grid options are remembered, so if ()it again, it will use the same grid configuration Mexico Tech Computer CenterTkinter reference: Layout managementPage 53.

9 Standard attributesBefore we look at the widgets, let s take a look at how some of their common attributes such as sizes, colors and fonts are specified. Each widget has a set ofoptionsthat affect its appearance and behavior attributessuch as fonts, colors, sizes, text labels, and such. You can specify options when calling the widget s constructor using keyword argu-ments such as text="PANIC!" or height=20 . After you have created a widget, you can later change any option by using thewidget ()method, and retrieve the current setting of any option by usingthe widget ()method. SeeUniversal widget methods, below, for more onthese DimensionsVarious lengths, widths, and other dimensions of widgets can be described in variousunits. If you set a dimension to an integer, it is assumed to be in pixels.

10 You can specify units by setting a dimension to a string containing a number followedby:ccentimetersiinchesmmillimete rspprinter s points ( ) Coordinate systemAs in most contemporary display systems, the origin of each coordinate system is at itsupper left corner, with thexcoordinate increasing toward the right, and theycoordinateincreasing toward the bottom:The base unit is the pixel, with the top left pixel having coordinates (0;0). Coordinatesthat you specify as integers are always expressed in pixels, but any coordinate may bespecified as a dimensioned quantity; seeDimensions, Mexico Tech Computer CenterTkinter reference: Standard attributesPage ColorsThere are two general ways to specify colors in Tkinter . You can use a string specifying the proportion of red, green, and blue in hexadecimaldigits:#rgbFour bits per color#rrggbbEight bits per color#rrrgggbbbTwelve bits per color#rrrrggggbbbbSixteen bits per colorFor example,"#fff"is white,"#000000"is black,"#000fff000"is pure green,and"#00ffff"is pure cyan (green plus blue).


Related search queries