1.使用Tkinter创建图形用户界面的步骤

(1)导入Tkinter模块,使用import Tkinter或from Tkinter import *

(2)创建顶层窗口对象容器,使用top = Tkinter.Tk()

(3)在顶层窗口对象上创建GUI对象

(4)将GUI对象与底层程序代码相连接

(5)进入主事件循环

例如:

# !/usr/bin/env python

import Tkinter

top = Tkinter.Tk()
label = Tkinter.Label(top, text="Hello, World")
label.pack()
Tkinter.mainloop()
# !/usr/bin/env python

import Tkinter
top = Tkinter.Tk()

hello_label = Tkinter.Label(top, text="Hello, World")
hello_label.pack()

quit_button = Tkinter.Button(top, text="Quit", command=top.quit,  bg="pink", fg="blue")
quit_button.pack(fill=Tkinter.X, expand=1)

Tkinter.mainloop()

例如:通过进度条改变文字的大小

# !/usr/bin/env python

#第一步:导入Tkinter类
import Tkinter

def resize(ev=None):
        '''通过进度条改变文字的大小'''
        hello_label.config(font="Helvetica -%d bold" % hello_scale.get())

#第二部:创建顶层窗口容器对象
top = Tkinter.Tk()
top.geometry("250x150")

#第三步:创建GUI对象
hello_label = Tkinter.Label(top, text="Hello, World", font="Helvetica -12 bold")
#第四步:将GUI对象与顶层代码连接
hello_label.pack(fill=Tkinter.Y, expand=1)

hello_scale = Tkinter.Scale(top, from_=10, to=40, orient=Tkinter.HORIZONTAL, command=resize)
hello_scale.set(12)
hello_scale.pack(fill=Tkinter.X, expand=1)

quit_button = Tkinter.Button(top, text="Quit", command=top.quit, activeforeground="white", activebackground="red")
quit_button.pack()

#第五步:进入主事件循环
Tkinter.mainloop()

例如:偏函数的使用

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from functools import partial
import Tkinter

top = Tkinter.Tk()
top.title("Button")

MyButton = partial(Tkinter.Button, top, bg="blue", fg="white")
button1 = MyButton(text="Button1")
button1.pack()

button2 = MyButton(text="Button2")
button2.pack()

button3 = MyButton(text="Quit", command=top.quit)
button3.pack(fill=Tkinter.X, expand=2)

Tkinter.mainloop()

Python图形用户界面的更多相关文章

  1. Python图形用户界面-Tkinter

    Tkinter是什么 python 特定的GUI界面,是一个图像的窗口,tkinter是python 自带的,可以编辑的GUI界面,我们可以用GUI 实现很多一个直观的功能,如何想开发一个计算器,如果 ...

  2. python学习笔记(十 一)、GUI图形用户界面

    python图形用户界面就是包含按钮.输入框.选择框等组件的窗口.主要依赖与工具包进行代码编写.python GUI工具包并发互斥的,你可以选择多个工具包进行安装,有极大选择空间.每个工具包都有不同用 ...

  3. python基础课程_2学习笔记3:图形用户界面

    图形用户界面 丰富的平台 写作Python GUI程序前,须要决定使用哪个GUI平台. 简单来说,平台是图形组件的一个特定集合.能够通过叫做GUI工具包的给定Python模块进行訪问. 工具包 描写叙 ...

  4. 以Tkinter模块来学习Python实现GUI(图形用户界面)编程

    tk是什么:它是一个图形库,支持多个操作系统,使用tcl语言开发的.tkinter是Python内置的模块, 与tk类似的第三方图形库(GUI库)还有很多,比如:Qt,GTK,wxWidget,wxP ...

  5. R python在无图形用户界面时保存图片

    在用python的matplotlib,和R中自带的作图,如果想保存图片时,当你有图形用户界面时是没有问题的,但是当没有图形用户界面时,会报错: 在R中,解决办法: https://blog.csdn ...

  6. python之GUI图形用户界面 2014-4-7

    #图形用户界面1.下载和安装wxPython2.创建并显示一个框架import wx #导入wxPythonapp=wx.App()win=wx.Frame(None)win.Show() #调用窗口 ...

  7. 图形用户界面入门:EasyGui - 零基础入门学习Python035

    图形用户界面入门:EasyGui 让编程改变世界 Change the world by program 今天我们来谈谈图形用户界面编程,也就是我们常说的GUI(Graphical User Inte ...

  8. 挺棒的七个Python图形应用GUI开发框架

    作为Pyhon开发者,你迟早都会碰到图形用户界面(GUI)应用开发任务,目前市场上有大量Python GUI开发框架可供选择,Python wiki GUI programming给出了超过30个跨平 ...

  9. GUI(图形用户界面)

    ylbtech-Miscellaneos:GUI(图形用户界面) A,返回顶部 1, 图形用户界面(Graphical User Interface,简称 GUI,又称图形用户接口)是指采用图形方式显 ...

随机推荐

  1. JSoup抓取本地页面

    File in = new File("C:/Users/li/Desktop/2.html"); Document doc01 = Jsoup.parse(in, "U ...

  2. mybatis之一对多

    今天主要话题围绕这么几个方面? mybatis一对多示例 sql优化策略 一.mybatis之一对多 在说一对多之前,顺便说一下一对一. 一对一,常见的例子,比如以常见的班级例子来说,一个班主任只属于 ...

  3. redis-trib.rb命令详解

    redis-trib.rb是官方提供的Redis Cluster的管理工具,无需额外下载,默认位于源码包的src目录下,但因该工具是用ruby开发的,所以需要准备相关的依赖环境. 准备redis-tr ...

  4. UART、SPI和I2C详解

    做单片机开发时UART,SPI和I2C都是我们最经常使用到的硬件接口,我收集了相关的具体材料对这三种接口进行了详细的解释. UART UART是一种通用串行数据总线,用于异步通信.该总线双向通信,可以 ...

  5. MVC5+EF6入门教程——实现动态创建数据库与登录验证

    详细步骤 创建文件夹,规划好项目目录 创建相关实体类 (Data Model) 创建 Database Context 创建Initializer, 使用EF初始化数据库,插入测试数据 实现数据库登录 ...

  6. 朱晔和你聊Spring系列S1E10:强大且复杂的Spring Security(含OAuth2三角色+三模式完整例子)

    Spring Security功能多,组件抽象程度高,配置方式多样,导致了Spring Security强大且复杂的特性.Spring Security的学习成本几乎是Spring家族中最高的,Spr ...

  7. NewZealand。。。

    秀个存在感...

  8. python-Requests + 正则表达式爬取猫眼电影

    github: https://github.com/LXL-YAN/Requests_Regular-Expressions-Crawl-CatEye-Movies

  9. poj2104 主席树裸题

    空间大小:n*lgn 复杂度:建树n*lgn  查询lgn #include <cstdio> #include <iostream> #include <algorit ...

  10. Selling Souvenirs CodeForces - 808E (分类排序后DP+贪心)

    E. Selling Souvenirs time limit per test 2 seconds memory limit per test 256 megabytes input standar ...