引:Python GUI编程(Tkinter)

Python提供了开发图形用户界面(GUI)的各种方案。下面列出最重要如下:

Tkinter:Tkinter的是Tk的GUI工具包,与Python附带的Python接口。在本教程中我们将看看这个选项.

wxPython:这是一个开源的Python接口的wxWindowshttp://wxpython.org.

JPython:JPython的是一个用于Java的Python端口,

这使得Python脚本在本地机器上的无缝接入到Java类库http://www.jython.org.

有很多可用它,我这里没有列出的其他接口。您可以通过网络找到它们.

Tkinter 编程:

TkInter是标准的Python GUI库。的Python与Tkinter的结合提供了一个快速和容易的方法来创建GUI应用程序。 Tkinter的提供了一个强大的面向对象的接口Tk的GUI工具包.

使用Tkinter创建一个GUI应用程序是一件容易的事。所有你需要做的是执行以下步骤:

导入Tkinter模块.

创建GUI应用程序的主窗口.

添加上述部件之一或更多的GUI应用程序.

进入主事件循环的由用户触发每个事件响应.

例子:

#!/usr/bin/python

import Tkinter

top = Tkinter.Tk()

# Code to add widgets will go here...

top.mainloop()

这将创建一个下面的窗口:

Tkinter的部件:

Tkinter的提供各种控件,如按钮,标签和文本框,一个GUI应用程序中使用。这些控件通常被称为部件.

目前有15种Tkinter的部件。我们提出这些部件以及一个简短的介绍,在下面的表:

OperatorDescription

Button  


The Button widget is used to display buttons in your application.

Canvas


The Canvas widget is used to draw shapes, such as lines, ovals, polygons, and rectangles, in your application.

Checkbutton


The Checkbutton widget is used to display a number of options as checkboxes. The user can select multiple options at a time.

Entry


The Entry widget is used to display a single-line text field for accepting values from a user.

Frame


The Frame widget is used as a container widget to organize other widgets.

Label


The Label widget is used to provide a single-line caption for other widgets. It can also contain images.

Listbox


The Listbox widget is used to provide a list of options to a user.

Menubutton


The Menubutton widget is used to display menus in your application.

Menu


The Menu widget is used to provide various commands to a user. These commands are contained inside Menubutton.

Message


The Message widget is used to display multiline text fields for accepting values from a user.

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.

Scale


The Scale widget is used to provide a slider widget.

Scrollbar


The Scrollbar widget is used to add scrolling capability to various widgets, such as list boxes.

Text


The Text widget is used to display text in multiple lines.

Toplevel


The Toplevel widget is used to provide a separate window container.

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.

PanedWindow


A PanedWindow is a container widget that may contain any number of panes, arranged horizontally or vertically.

LabelFrame


A labelframe is a simple container widget. Its primary purpose is to act as a spacer or container for complex window layouts.

tkMessageBox


This module is used to display message boxes in your applications.

标准属性:

让我们来看看如何他们的一些共同的属性。如大小,颜色和字体指定.

Dimensions

Colors

Fonts

Anchors

Relief styles

Bitmaps

Cursors

几何管理:

Tkinter的部件有特定几何形状的管理方法,整个小部件父控件区域组织的目的。 Tkinter的公开以下几何经理类:包装,网格,位置.

pack()方法- 这个的几何管理器组织之前,将其放置在他们的父widget块部件.

grid()方法- 这的几何管理器组织表状结构中的小部件的父部件.

place()方法-这个的几何管理器组织放置在一个特定的位置,在他们的父widget部件.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 冰心 我从不肯妄弃了一张纸 总是留着,留着 叠成一只一只很小的船儿 从舟上抛下在海里 ...
    孤独救世主阅读 345评论 0 0
  • 讲真,此刻的我,心里有一些愤怒和不满。 轩轩遇到事情不开心了翘嘴巴,立马被教育不可以这样,嘴巴翘起来多难看。轩轩皱...
    白雪群阅读 328评论 0 0
  • 每当遭遇迷茫之时,总会回到梦想出发的地方——北京。散心也好,寻回当初的激情也罢,每次回到这里,都按耐不住那颗欢欣雀...
    格桑月阅读 547评论 0 1
  • 春来观花,看万物复苏,四野碧现,草长莺飞。秋来赏叶,听秋风肃杀,看万叶飘零。 在乍暖还寒的时节,朋友圈里早...
    lovingyourself阅读 422评论 4 2
  • 有时认识别人很简单,读懂自己很难。我想当我读懂自己时,便能读懂哲学、读懂这个世界。 基督教信徒把自己的烦恼抛给上帝...
    言卜阅读 448评论 0 0