📅  最后修改于: 2020-12-23 05:05:48             🧑  作者: Mango
Python提供了多种开发图形用户界面(GUI)的选项。下面列出了最重要的功能。
Tkinter的– Tkinter的是Python接口附带的Python Tk的GUI工具包。我们将在本章中查找此选项。
wxPython-这是wxWidgets GUI工具包的开源Python界面。您可以在此处找到有关WxPython的完整教程。
PyQt-这也是流行的跨平台Qt GUI库的Python接口。 TutorialsPoint在这里有一个有关PyQt的很好的教程。
JPython -JPython是Java的Python端口,可让Python脚本无缝访问本地计算机http://www.jython.org上的Java类库。
还有许多其他可用接口,您可以在网上找到它们。
Tkinter是Python的标准GUI库。Python与Tkinter结合使用时,可以轻松快速地创建GUI应用程序。 Tkinter为Tk GUI工具包提供了强大的面向对象的界面。
使用Tkinter创建GUI应用程序很容易。您需要做的就是执行以下步骤-
导入Tkinter模块。
创建GUI应用程序主窗口。
将一个或多个上述小部件添加到GUI应用程序。
进入主事件循环以对用户触发的每个事件采取措施。
#!/usr/bin/python3
import tkinter # note that module name has changed from Tkinter in Python 2 to tkinter in Python 3
top = tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()
这将创建以下窗口-
Tkinter提供了各种控件,例如GUI应用程序中使用的按钮,标签和文本框。这些控件通常称为小部件。
Tkinter当前有15种类型的小部件。下表中列出了这些小部件以及简要说明-
Sr.No. | Operator & Description |
---|---|
1 |
Button
The Button widget is used to display the buttons in your application. |
2 |
Canvas
The Canvas widget is used to draw shapes, such as lines, ovals, polygons and rectangles, in your application. |
3 |
Checkbutton
The Checkbutton widget is used to display a number of options as checkboxes. The user can select multiple options at a time. |
4 |
Entry
The Entry widget is used to display a single-line text field for accepting values from a user. |
5 |
Frame
The Frame widget is used as a container widget to organize other widgets. |
6 |
Label
The Label widget is used to provide a single-line caption for other widgets. It can also contain images. |
7 |
Listbox
The Listbox widget is used to provide a list of options to a user. |
8 |
Menubutton
The Menubutton widget is used to display menus in your application. |
9 |
Menu
The Menu widget is used to provide various commands to a user. These commands are contained inside Menubutton. |
10 |
Message
The Message widget is used to display multiline text fields for accepting values from a user. |
11 |
Radiobutton
The Radiobutton widget is used to display a number of options as radio buttons. The user can select only one option at a time. |
12 |
Scale
The Scale widget is used to provide a slider widget. |
13 |
Scrollbar
The Scrollbar widget is used to add scrolling capability to various widgets, such as list boxes. |
14 |
Text
The Text widget is used to display text in multiple lines. |
15 |
Toplevel
The Toplevel widget is used to provide a separate window container. |
16 |
Spinbox
The Spinbox widget is a variant of the standard Tkinter Entry widget, which can be used to select from a fixed number of values. |
17 |
PanedWindow
A PanedWindow is a container widget that may contain any number of panes, arranged horizontally or vertically. |
18 |
LabelFrame
A labelframe is a simple container widget. Its primary purpose is to act as a spacer or container for complex window layouts. |
19 |
tkMessageBox
This module is used to display message boxes in your applications. |
让我们看看如何指定它们的一些常见属性,例如大小,颜色和字体。
所有Tkinter窗口小部件都可以访问特定的几何图形管理方法,其目的是在整个父窗口小部件区域中组织窗口小部件。 Tkinter公开以下几何图形管理器类:包装,网格和位置。