Python Tkinter 類__Python

來源:互聯網
上載者:User
Tkinter Classes Widget classes

Tkinter supports 15 core widgets:

Tkinter 支援15個核心組件: Button A simple button, used to execute a command or other operation. 按鈕:一個簡單的按鈕,用於執行一個命令列或者其他動作。 Canvas Structured graphics. This widget can be used to draw graphs and plots, create graphics editors, and to implement custom widgets. 畫布:結構化映像。這個組件可以被使用者畫映像和圖表,建立影像編輯器和部署定製化組件。
Checkbutton Represents a variable that can have two distinct values. Clicking the button toggles between the values. 選擇按鈕:代表一個變數可以有兩個相反的值。通過點擊按鈕可以在兩個值之間切換。 Entry A text entry field. 文本區:文本輸入地區 Frame A container widget. The frame can have a border and a background, and is used to group other widgets when creating an application or dialog layout. 架構:容器組件。容器可以有一個邊框和背景。在建立一個應用或者會話布局的時候使用者群分其他組件。 Label Displays a text or an image. 標籤:顯示一個文本或者映像。 Listbox Displays a list of alternatives. The listbox can be configured to get radiobutton or checklist behavior. 列表框:顯示一列候選值,可以被配置成單選或者複選。 Menu A menu pane. Used to implement pulldown and popup menus. 菜單:一個菜單方框。使用者部署下拉或者快顯功能表。 Menubutton A menubutton. Used to implement pulldown menus. 功能表按鈕:使用者部署下拉式功能表。 Message Display a text. Similar to the label widget, but can automatically wrap text to a given width or aspect ratio. 訊息:顯示一個文本。跟標籤組件類似,但可以自動的把文本封裝成給定的寬度或比例。 Radiobutton Represents one value of a variable that can have one of many values. Clicking the button sets the variable to that value, and clears all other radiobuttons associated with the same variable. 選項按鈕:表示一個擁有多個值的變數的一個值。點擊這個按鈕可以把在這個變數設為相應的值,同時會清除這個變數關聯的其他選項按鈕。 Scale Allows you to set a numerical value by dragging a “slider”. 滑動條:允許通過拖到滑塊去設定一個數字化的數值。 Scrollbar Standard scrollbars for use with canvas, entry, listbox, and text widgets. 捲軸:標準的捲軸使用在畫布,文本輸入區,列表框和文本組件。 Text Formatted text display. Allows you to display and edit text with various styles and attributes. Also supports embedded images and windows. 文本:格式化文本顯示。允許以各式各樣的格式和屬性去顯示和編輯文本。支援嵌入的映像和視窗。 Toplevel A container widget displayed as a separate, top-level window. 頂層視窗,一個顯示為獨立的頂層視窗的容器組件。

In Python 2.3 (Tk 8.4), the following widgets were added:

Python2.3(Tk8.4)中添加了下面的組件: LabelFrame A variant of the Frame widget that can draw both a border and a title. 標籤框:架構組件的一個變種,可以畫邊框和標題。 PanedWindow A container widget that organizes child widgets in resizable panes. 面板:一個在可調整大小的視窗組織子組件的容器組件。 Spinbox A variant of the Entry widget for selecting values from a range or an ordered set. 旋轉框:文本輸入框的一個變種,使用者從一個排列或有序集合中選擇數值。

Also note that there’s no widget class hierarchy in Tkinter; all widget classes are siblings in the inheritance tree.

可以注意到在Tkinter中沒有組件類等級,在繼承樹裡面所有的組件類都是兄弟姐妹。

All these widgets provide the Misc and geometry management methods, the configuration management methods, and additional methods defined by the widget itself. In addition, the Toplevel class also provides the window manager interface. This means that a typical widget class provides some 150 methods.

所有的組件提供Misc和幾何管理方法,組態管理方法和組件自身定義的其他方法。此外,toplevel類還提供了視窗管理介面。這就意味著一個典型的組件類提供差不多150種方法。 Mixins

The Tkinter module provides classes corresponding to the various widget types in Tk, and a number of mixin and other helper classes (a mixin is a class designed to be combined with other classes using multiple inheritance). When you use Tkinter, you should never access the mixin classes directly.

Tkinter模組提供對應Tk中各種組件類型的類和一系列mixin和其他協助類(mixin類使用者通過多重繼承整個其他類)。 Implementation mixins

The Misc class is used as a mixin by the root window and widget classes. It provides a large number of Tk and window related services, which are thus available for all Tkinter core widgets. This is done by delegation; the widget simply forwards the request to the appropriate internal object.

Misc類被根視窗和組件類用作一個mixin。它提供了大量的Tk和視窗的服務,這些服務隊Tkinter核心組件非常有協助。這些通過授權來實現:組件只需要向合適的內部對象傳遞需求即可。

The Wm class is used as a mixin by the root window and Toplevel widget classes. It provides window manager services, also by delegation.

Wm類被根視窗和toplevel組件用作一個mixin,它通過授權提供視窗管理服務。

Using delegation like this simplifies your application code: once you have a widget, you can access all parts of Tkinter using methods on the widget instance.

想這樣的授權簡化了應用代碼:一旦擁有一個組件,就可以使用組件執行個體的方法訪問Tkinter的所有部分。 Geometry mixins

The Grid, Pack, and Place classes are used as mixins by the widget classes. They provide access to the various geometry managers, also via delegation.

Grid、pack、Place類被組件用作mixin。它們通過授權提供了訪問各種幾何管理器的許可權。 Grid The grid geometry manager allows you to create table-like layouts, by organizing the widgets in a 2-dimensional grid. To use this geometry manager, use the  grid method. 網格:網格幾何管理器可以通過把組件組織成一個二維網格的方式建立圖表樣的布局。使用grid方法可以使用這種幾何管理。 Pack The pack geometry manager lets you create a layout by “packing” the widgets into a parent widget, by treating them as rectangular blocks placed in a frame. To use this geometry manager for a widget, use the  pack method on that widget to set things up. 包幾何管理可以通過把組件和父組件打包去建立布局,把它們當做位於架構裡矩形塊。
Place The place geometry manager lets you explicitly place a widget in a given position. To use this geometry manager, use the  place method. place幾個管理器可以準確的把組件定位到一個給定的位置。可以使用place方法去使用這個幾個管理器。 Widget configuration management

The Widget class mixes the Misc class with the geometry mixins, and adds configuration management through the cget and configure methods, as well as through a partial dictionary interface. The latter can be used to set and query individual options, and is explained in further detail in the next chapter.

Widget類通過幾個minixs混合Misc類,通過cget和configure方法添加了組態管理。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.