- Python Tkinter Button
- Python Tkinter Treeview
- Python Tkinter Button
- Python Tkinter Vs Qt5
- Python Tkinter Ttk
Python - Tkinter Anchors - Anchors are used to define where text is positioned relative to a reference point. Tkinter (GUI Programming) Tkinter is a graphical user interface (GUI) module for Python, you can make desktop apps with Python. You can make windows, buttons, show text and images amongst other things. Tk and Tkinter apps can run on most Unix platforms. This also works on Windows and Mac OS X. The module Tkinter is an interface to the Tk GUI. Tkinter is the Python port for Tcl-Tk GUI toolkit developed by Fredrik Lundh. This module is bundled with standard distributions of Python for all platforms. PyQtis, the Python interface to Qt, is a very popular cross-platform GUI framework. PyGTK is the module that ports Python to another popular GUI widget toolkit called GTK. Tk.call method is the Tkinter interface to tcl interpreter. We could run a tcl command by using this call method. It is handy when the Tkinter wrapper couldn’t have access to some tcl/tk features.
Deprecated since version 3.6: This Tk extension is unmaintained and should not be used in new code. Use
tkinter.tix (Tk Interface Extension) module provides an additionalrich set of widgets. Although the standard Tk library has many useful widgets,they are far from complete. The
tkinter.tix library provides most of thecommonly needed widgets that are missing from standard Tk:
Control (a.k.a. SpinBox) and an assortment ofscrollable widgets.
tkinter.tix also includes many more widgets that are generally useful ina wide range of applications:
PanedWindow, etc; there are more than 40 of them.
With all these new widgets, you can introduce new interaction techniques intoapplications, creating more useful and more intuitive user interfaces. You candesign your application by choosing the most appropriate widgets to match thespecial needs of your application and users.
The home page for
Tix. This includes links to additional documentationand downloads.
On-line version of the man pages and reference material.
On-line version of the programmer’s reference material.
Tix applications for development of Tix and Tkinter programs. Tide applicationswork under Tk or Tkinter, and include TixInspect, an inspector toremotely modify and debug Tix/Tk/Tkinter applications.
Tk(screenName=None, baseName=None, className='Tix')¶
Toplevel widget of Tix which represents mostly the main window of anapplication. It has an associated Tcl interpreter.
Classes in the
tkinter.tix module subclasses the classes in the
tkinter. The former imports the latter, so to use
tkinter.tixwith Tkinter, all you need to do is to import one module. In general, youcan just import
tkinter.tix, and replace the toplevel call to
tkinter.tix, you must have the Tix widgets installed, usuallyalongside your installation of the Tk widgets. To test your installation, trythe following:
Tixintroduces over 40 widget classes to the
A Balloon thatpops up over a widget to provide help. When the user moves the cursor inside awidget to which a Balloon widget has been bound, a small pop-up window with adescriptive message will be shown on the screen.
The ButtonBoxwidget creates a box of buttons, such as is commonly used for
The ComboBoxwidget is similar to the combo box control in MS Windows. The user can select achoice by either typing in the entry subwidget or selecting from the listboxsubwidget.
The Controlwidget is also known as the
SpinBox widget. The user can adjust thevalue by pressing the two arrow buttons or by entering the value directly intothe entry. The new value will be checked against the user-defined upper andlower limits.
The LabelEntrywidget packages an entry widget and a label into one mega widget. It canbe used to simplify the creation of “entry-form” type of interface.
The LabelFramewidget packages a frame widget and a label into one mega widget. To createwidgets inside a LabelFrame widget, one creates the new widgets relative to the
frame subwidget and manage them inside the
The Meter widgetcan be used to show the progress of a background job which may take a long timeto execute.
The OptionMenucreates a menu button of options.
The PopupMenuwidget can be used as a replacement of the
tk_popup command. The advantageof the
PopupMenu widget is it requires less application codeto manipulate.
The Select widgetis a container of button subwidgets. It can be used to provide radio-box orcheck-box style of selection options for the user.
The StdButtonBoxwidget is a group of standard buttons for Motif-like dialog boxes.
The DirListwidget displays a list view of a directory, its previous directories and itssub-directories. The user can choose one of the directories displayed in thelist or change to another directory.
The DirTreewidget displays a tree view of a directory, its previous directories and itssub-directories. The user can choose one of the directories displayed in thelist or change to another directory.
The DirSelectDialogwidget presents the directories in the file system in a dialog window. The usercan use this dialog window to navigate through the file system to select thedesired directory.
DirSelectBox is similar to the standard Motif(TM)directory-selection box. It is generally used for the user to choose adirectory. DirSelectBox stores the directories mostly recently selected intoa ComboBox widget so that they can be quickly selected again.
The ExFileSelectBoxwidget is usually embedded in a tixExFileSelectDialog widget. It provides aconvenient method for the user to select files. The style of the
ExFileSelectBox widget is very similar to the standard file dialog onMS Windows 3.1.
The FileSelectBoxis similar to the standard Motif(TM) file-selection box. It is generally usedfor the user to choose a file. FileSelectBox stores the files mostly recentlyselected into a
ComboBox widget so that they can be quickly selectedagain.
Python Tkinter Button
The FileEntrywidget can be used to input a filename. The user can type in the filenamemanually. Alternatively, the user can press the button widget that sits next tothe entry, which will bring up a file selection dialog.
The HList widgetcan be used to display any data that have a hierarchical structure, for example,file system directory trees. The list entries are indented and connected bybranch lines according to their places in the hierarchy.
The CheckListwidget displays a list of items to be selected by the user. CheckList actssimilarly to the Tk checkbutton or radiobutton widgets, except it is capable ofhandling many more items than checkbuttons or radiobuttons.
The Tree widgetcan be used to display hierarchical data in a tree form. The user can adjust theview of the tree by opening or closing parts of the tree.
The TList widgetcan be used to display data in a tabular format. The list entries of a
TList widget are similar to the entries in the Tk listbox widget. Themain differences are (1) the
TList widget can display the list entriesin a two dimensional format and (2) you can use graphical images as well asmultiple colors and fonts for the list entries.
The PanedWindowwidget allows the user to interactively manipulate the sizes of several panes.The panes can be arranged either vertically or horizontally. The user changesthe sizes of the panes by dragging the resize handle between two panes.
The ListNoteBookwidget is very similar to the
TixNoteBook widget: it can be used todisplay many windows in a limited space using a notebook metaphor. The notebookis divided into a stack of pages (windows). At one time only one of these pagescan be shown. The user can navigate through these pages by choosing the name ofthe desired page in the
The NoteBookwidget can be used to display many windows in a limited space using a notebookmetaphor. The notebook is divided into a stack of pages. At one time only one ofthese pages can be shown. The user can navigate through these pages by choosingthe visual “tabs” at the top of the NoteBook widget.
tkinter.tix module adds:
pixmapcapabilities to all
tkinterwidgets to createcolor images from XPM files.
Compound imagetypes can be used to create images that consists of multiple horizontal lines;each line is composed of a series of items (texts, bitmaps, images or spaces)arranged from left to right. For example, a compound image can be used todisplay a bitmap and a text string simultaneously in a Tk
The InputOnlywidgets are to accept inputs from the user, which can be done with the
bindcommand (Unix only).
Form Geometry Manager¶
tkinter by providing:
The Form geometrymanager based on attachment rules for all Tk widgets.
The tix commands provideaccess to miscellaneous elements of
Tix’s internal state and the
Tix application context. Most of the information manipulated by thesemethods pertains to the application as a whole, or to a screen or display,rather than to a particular window.
To view the current settings, the common usage is:
Query or modify the configuration options of the Tix application context. If nooption is specified, returns a dictionary all of the available options. Ifoption is specified with no value, then the method returns a list describing theone named option (this list will be identical to the corresponding sublist ofthe value returned if no option is specified). If one or more option-valuepairs are specified, then the method modifies the given option(s) to have thegiven value(s); in this case the method returns an empty string. Option may beany of the configuration options.
Returns the current value of the configuration option given by option. Optionmay be any of the configuration options.
Locates a bitmap file of the name
name in one of the bitmapdirectories (see the
tix_addbitmapdir() method). By using
tix_getbitmap(), you can avoid hard coding the pathnames of the bitmapfiles in your application. When successful, it returns the complete pathname ofthe bitmap file, prefixed with the character
@. The returned value can beused to configure the
bitmap option of the Tk and Tix widgets.
Tix maintains a list of directories under which the
tix_getbitmap() methods will search for image files. The standard bitmapdirectory is
tix_addbitmapdir() methodadds directory into this list. By using this method, the image files of anapplications can also be located using the
Returns the file selection dialog that may be shared among different calls fromthis application. This method will create a file selection dialog widget whenit is called the first time. This dialog will be returned by all subsequentcalls to
tix_filedialog(). An optional dlgclass parameter can be passedas a string to specified what type of file selection dialog widget is desired.Possible options are
Locates an image file of the name
name.ppm in one of the bitmap directories (see the
tix_addbitmapdir() method above). If more than one file with the same name(but different extensions) exist, then the image type is chosen according to thedepth of the X display: xbm images are chosen on monochrome displays and colorimages are chosen on color displays. By using
tix_getimage(), you canavoid hard coding the pathnames of the image files in your application. Whensuccessful, this method returns the name of the newly created image, which canbe used to configure the
image option of the Tk and Tix widgets.
Gets the options maintained by the Tix scheme mechanism.
tix_resetoptions(newScheme, newFontSet[, newScmPrio])¶
Resets the scheme and fontset of the Tix application to newScheme andnewFontSet, respectively. This affects only those widgets created after thiscall. Therefore, it is best to call the resetoptions method before the creationof any widgets in a Tix application.
The optional parameter newScmPrio can be given to reset the priority level ofthe Tk options set by the Tix schemes.
Because of the way Tk handles the X option database, after Tix has been hasimported and inited, it is not possible to reset the color schemes and font setsusing the
tix_config() method. Instead, the
tix_resetoptions()method must be used.
Tkinter tutorial provides basic and advanced concepts of Python Tkinter. Our Tkinter tutorial is designed for beginners and professionals.
Python provides the standard library Tkinter for creating the graphical user interface for desktop based applications.
Developing desktop based applications with python Tkinter is not a complex task. An empty Tkinter top-level window can be created by using the following steps.
- import the Tkinter module.
- Create the main application window.
- Add the widgets like labels, buttons, frames, etc. to the window.
- Call the main event loop so that the actions can take place on the user's computer screen.
Python Tkinter Treeview
There are various widgets like button, canvas, checkbutton, entry, etc. that are used to build the python GUI applications.
|1||Button||The Button is used to add various kinds of buttons to the python application.|
|2||Canvas||The canvas widget is used to draw the canvas on the window.|
|3||Checkbutton||The Checkbutton is used to display the CheckButton on the window.|
|4||Entry||The entry widget is used to display the single-line text field to the user. It is commonly used to accept user values.|
|5||Frame||It can be defined as a container to which, another widget can be added and organized.|
|6||Label||A label is a text used to display some message or information about the other widgets.|
|7||ListBox||The ListBox widget is used to display a list of options to the user.|
|8||Menubutton||The Menubutton is used to display the menu items to the user.|
|9||Menu||It is used to add menu items to the user.|
|10||Message||The Message widget is used to display the message-box to the user.|
|11||Radiobutton||The Radiobutton is different from a checkbutton. Here, the user is provided with various options and the user can select only one option among them.|
|12||Scale||It is used to provide the slider to the user.|
|13||Scrollbar||It provides the scrollbar to the user so that the user can scroll the window up and down.|
|14||Text||It is different from Entry because it provides a multi-line text field to the user so that the user can write the text and edit the text inside it.|
|14||Toplevel||It is used to create a separate window container.|
|15||Spinbox||It is an entry widget used to select from options of values.|
|16||PanedWindow||It is like a container widget that contains horizontal or vertical panes.|
|17||LabelFrame||A LabelFrame is a container widget that acts as the container|
|18||MessageBox||This module is used to display the message-box in the desktop based applications.|
Python Tkinter Geometry
The Tkinter geometry specifies the method by using which, the widgets are represented on display. The python Tkinter provides the following geometry methods.
- The pack() method
- The grid() method
- The place() method
Let's discuss each one of them in detail.
Python Tkinter pack() method
The pack() widget is used to organize widget in the block. The positions widgets added to the python application using the pack() method can be controlled by using the various options specified in the method call.
However, the controls are less and widgets are generally added in the less organized manner.
The syntax to use the pack() is given below.
A list of possible options that can be passed in pack() is given below.
- expand: If the expand is set to true, the widget expands to fill any space.
- Fill: By default, the fill is set to NONE. However, we can set it to X or Y to determine whether the widget contains any extra space.
- size: it represents the side of the parent to which the widget is to be placed on the window.
Python Tkinter grid() method
The grid() geometry manager organizes the widgets in the tabular form. We can specify the rows and columns as the options in the method call. We can also specify the column span (width) or rowspan(height) of a widget.
This is a more organized way to place the widgets to the python application. The syntax to use the grid() is given below.
Python Tkinter Button
A list of possible options that can be passed inside the grid() method is given below.
The column number in which the widget is to be placed. The leftmost column is represented by 0.
The width of the widget. It represents the number of columns up to which, the column is expanded.
- ipadx, ipady
It represents the number of pixels to pad the widget inside the widget's border.
- padx, pady
It represents the number of pixels to pad the widget outside the widget's border.
The row number in which the widget is to be placed. The topmost row is represented by 0.
The height of the widget, i.e. the number of the row up to which the widget is expanded.
If the cell is larger than a widget, then sticky is used to specify the position of the widget inside the cell. It may be the concatenation of the sticky letters representing the position of the widget. It may be N, E, W, S, NE, NW, NS, EW, ES.
Python Tkinter place() method
The place() geometry manager organizes the widgets to the specific x and y coordinates.
A list of possible options is given below.
Python Tkinter Vs Qt5
- Anchor: It represents the exact position of the widget within the container. The default value (direction) is NW (the upper left corner)
- bordermode: The default value of the border type is INSIDE that refers to ignore the parent's inside the border. The other option is OUTSIDE.
- height, width: It refers to the height and width in pixels.
- relheight, relwidth: It is represented as the float between 0.0 and 1.0 indicating the fraction of the parent's height and width.
- relx, rely: It is represented as the float between 0.0 and 1.0 that is the offset in the horizontal and vertical direction.
- x, y: It refers to the horizontal and vertical offset in the pixels.
Python Tkinter Ttk
Before learning Tkinter, you must have the basic knowledge of Python.
Our Python Tkinter tutorial is designed to help beginners and professionals.
We assure that you will not find any problem in this Tkinter tutorial. But if there is any mistake, please post the problem in contact form.