Python Tkinter 图形组件介绍
1、 窗口 Tkinter.Tk()
# -*- coding: UTF-8 -*-
import Tkinter myWindow = Tkinter.Tk()
myWindow.title('南风丶轻语')
myWindow.geometry('400x500')
myWindow.mainloop()
运行结果

2、 标签 Label Tkinter.Label()
# -*- coding: UTF-8 -*-
import Tkinter myWindow = Tkinter.Tk()
myWindow.title('南风丶轻语')
myWindow.geometry('400x500') textVar = Tkinter.StringVar()
textVar.set('我是一个标签')
mylabel = Tkinter.Label(myWindow, bg='yellow', width=20, height=1,textvariable=textVar)
mylabel.pack() myWindow.mainloop()
运行结果

3、 按钮 Tkinter.Button()
# -*- coding: UTF-8 -*-
import Tkinter myWindow = Tkinter.Tk()
myWindow.title('南风丶轻语')
myWindow.geometry('400x500') textVar = Tkinter.StringVar()
textVar.set('我是一个标签')
mylabel = Tkinter.Label(myWindow, bg='yellow', width=20, height=1,textvariable=textVar)
mylabel.pack() print type(textVar.get()) clickFlag = False
def clickEvet():
global clickFlag
if clickFlag == False:
textVar.set('我是被点击后的标签')
clickFlag = True
else:
textVar.set('我是一个标签')
clickFlag = False myButton = Tkinter.Button(myWindow, width=10, height=1,text='点击', command=clickEvet)
myButton.pack() myWindow.mainloop()
运行结果

4、 输入框 Tkinter.Entry()
备注 : 程序功能为点击按钮,标签显示 entry 中输入的内容
# -*- coding: UTF-8 -*-
import Tkinter myWindow = Tkinter.Tk()
myWindow.title('南风丶轻语')
myWindow.geometry('400x500') textVar = Tkinter.StringVar()
textVar.set('我是一个标签')
mylabel = Tkinter.Label(myWindow, bg='yellow', width=20, height=1,textvariable=textVar)
mylabel.pack() def clickEvet():
textVar.set(myEntry.get()) myButton = Tkinter.Button(myWindow, width=10, height=1,text='点击', command=clickEvet)
myButton.pack() myEntry = Tkinter.Entry(myWindow, width=20,)
myEntry.pack() myWindow.mainloop()
运行结果

5、 文本框
备注 : 实现功能为点击按钮,文本框插入数据(插入位置可以是鼠标位置,也可以是末尾,我们用两个按钮控制实现该效果)
# -*- coding: UTF-8 -*-
import Tkinter myWindow = Tkinter.Tk()
myWindow.title('南风丶轻语')
myWindow.geometry('400x500') myText = Tkinter.Text(myWindow, height=5, show=None)
myText.pack() def clickEvet1():
myText.insert('insert', '鼠标位置插入数据') def clickEvet2():
myText.insert('end', '末尾插入数据') myButton = Tkinter.Button(myWindow, width=10, height=1,text='鼠标插入', command=clickEvet1)
myButton.pack() myButton2 = Tkinter.Button(myWindow, width=10, height=1,text='末尾插入', command=clickEvet2)
myButton2.pack() myWindow.mainloop()
运行结果

6、 listBox
备注 : 点击按钮,实现文本框显示选中的 listBox 的内容
# -*- coding: UTF-8 -*-
import Tkinter myWindow = Tkinter.Tk()
myWindow.title('南风丶轻语')
myWindow.geometry('400x500') myText = Tkinter.Text(myWindow, height=5, show=None)
myText.pack() def clickEvet():
myText.insert('end', myListBox.get(myListBox.curselection())) myButton2 = Tkinter.Button(myWindow, width = 10, height = 1,text = '点击', command = clickEvet)
myButton2.pack() listBoxVar = Tkinter.StringVar()
listBoxVar.set((11, 22, 33, 'tan'))
myListBox = Tkinter.Listbox(myWindow, listvariable = listBoxVar)
myListBox.pack() myWindow.mainloop()
运行结果

7、CheckBox
备注:实现选中 CheckBox, 标签中显示选中内容
# -*- coding: UTF-8 -*-
import Tkinter myWindow = Tkinter.Tk()
myWindow.title('CheckButton Test Window')
myWindow.geometry('430x430') labelText = Tkinter.StringVar()
lable = Tkinter.Label(myWindow, textvariable=labelText, bg='yellow', width=30, height=1)
lable.pack(side='top') def chooseEvent():
if (chooseFirst.get() == 1) and (chooseSecond.get() == 0) and (chooseThird.get() == 0):
labelText.set('Tan')
elif (chooseFirst.get() == 0) and (chooseSecond.get() == 1) and (chooseThird.get() == 0):
labelText.set('Xiao')
elif (chooseFirst.get() == 0) and (chooseSecond.get() == 0) and (chooseThird.get() == 1):
labelText.set('Hui')
elif (chooseFirst.get() == 1) and (chooseSecond.get() == 1) and (chooseThird.get() == 0):
labelText.set('TanXiao')
elif (chooseFirst.get() == 1) and (chooseSecond.get() == 0) and (chooseThird.get() == 1):
labelText.set('TanHui')
elif (chooseFirst.get() == 0) and (chooseSecond.get() == 1) and (chooseThird.get() == 1):
labelText.set('XiaoHui')
elif (chooseFirst.get() == 1) and (chooseSecond.get() == 1) and (chooseThird.get() == 1):
labelText.set('TanXiaoHui')
else:
labelText.set('') chooseFirst = Tkinter.IntVar()
checkButton1 = Tkinter.Checkbutton(myWindow, text='Tan', variable=chooseFirst, onvalue=1, offvalue=0, command=chooseEvent)
checkButton1.place(x=200, y=22)
chooseSecond = Tkinter.IntVar()
checkButton2 = Tkinter.Checkbutton(myWindow, text='Xiao', variable=chooseSecond, onvalue=1, offvalue=0, command=chooseEvent)
checkButton2.place(x=200, y=44)
chooseThird = Tkinter.IntVar()
checkButton3 = Tkinter.Checkbutton(myWindow, text='Hui', variable=chooseThird, onvalue=1, offvalue=0, command=chooseEvent)
checkButton3.place(x=200, y=66) myWindow.mainloop()
运行结果

Python Tkinter 图形组件介绍的更多相关文章
- python Tkinter图形用户编程简单学习(一)
Events(事件) Events are given as strings, using a special event syntax:事件以字符串的方式给出,使用特殊的事件语法:<modif ...
- python的re模块一些方法 && Tkinter图形界面设计 && 终止python运行函数 && python读写文件 && python一旦给字符串赋值就不能单独改变某个字符,除非重新给变量赋值
Tkinter图形界面设计见:https://www.cnblogs.com/pywjh/p/9527828.html#radiobutton 终止python运行函数: 采用sys.exit(0)正 ...
- Tkinter图形界面设计(GUI)
[因为这是我第一个接触的GUI图形界面python库,现在也不用了,所以大多数内容都来自之前花 钱买的一些快速入门的内容,可以当作简单的知识点查询使用] 在此声明:内容来自微信公众号GitChat,付 ...
- 高效而稳定的企业级.NET Office 组件Spire(.NET组件介绍之二)
在项目开发中,尤其是企业的业务系统中,对文档的操作是非常多的,有时几乎给人一种错觉的是”这个系统似乎就是专门操作文档的“.毕竟现在的很多办公中大都是在PC端操作文档等软件,在这些庞大而繁重的业务中,单 ...
- 一款开源免费的.NET文档操作组件DocX(.NET组件介绍之一)
在目前的软件项目中,都会较多的使用到对文档的操作,用于记录和统计相关业务信息.由于系统自身提供了对文档的相关操作,所以在一定程度上极大的简化了软件使用者的工作量. 在.NET项目中如果用户提出了相关文 ...
- 数百个 HTML5 例子学习 HT 图形组件 – 3D建模篇
http://www.hightopo.com/demo/pipeline/index.html <数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇>里提到 HT 很 ...
- 数百个 HTML5 例子学习 HT 图形组件 – 3D 建模篇
http://www.hightopo.com/demo/pipeline/index.html <数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇>里提到 HT 很 ...
- 数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇
<数百个 HTML5 例子学习 HT 图形组件 – 拓扑图篇>一文让读者了解了 HT的 2D 拓扑图组件使用,本文将对 HT 的 3D 功能做个综合性的介绍,以便初学者可快速上手使用 HT ...
- 数百个 HTML5 例子学习 HT 图形组件 – 拓扑图篇
HT 是啥:Everything you need to create cutting-edge 2D and 3D visualization. 这口号是当年心目中的产品方向,接着就朝这个方向慢慢打 ...
随机推荐
- Project configuration is not up-to-date with pom.xml.错误
完整错误信息:Description Resource Path Location TypeProject configuration is not up-to-date with pom.xml. ...
- [书籍精读]《React Native精解与实战》精读笔记分享
写在前面 书籍介绍:本书由架构师撰写,包含ReactNative框架底层原理,以及与iOS.Android混合开发案例,精选了大量实例代码,方便读者快速学习.主要内容分为两大部分,第1部分" ...
- Flask基础-01.Flask简介
Flask简介 Web应用程序作用 Web(World Wide Web)诞生最初的目的,是为了利用互联网交流工作文档. 关于Web框架 1. 什么是Web框架? 1. 已经封装好了一段代码,协助程序 ...
- JavaScript中的作用域和作用域链(边学边写)[看着别人的博客纯手敲]
作用域是JavaScript最重要的概念之一,想要学好JavaScript就需要理解JavaScript作用域和作用域的工作原理.今天这篇文章对JavaScript作用域和作用域链简单的介绍,希望能帮 ...
- overload 与override的区别
Override 是重写: 方法名称.参数个数,类型,顺序,返回值类型都是必须和父类方法一致的.它的关系是父子关系Overload 是重载: 方法名称不变,其余的都是可以变更的.它的关系是同一个类 ...
- google无法播放mp4 chrome无法播放h264
写在前面 我在chrome上无法播放h264+Acc的mp4,在firefox.ie都可以播放,而且此mp4在vlc终可以正常播放. 视频链接:http://106.14.221.185:7001/p ...
- Chrome 浏览器安装 ChroPath 插件
1.下载地址 http://www.cnplugins.com/devtool/chropath/download.html 2.安装方法 a.把下载的文件更改后缀名变为压缩包,然后解压到本地:如下图 ...
- testNG 问题总结
1. Eclipse中TestNG报告乱码问题 在eclipse 安装根目录下的eclipse.ini 文件,在最后增加 -Dfile.encoding=UTF-8
- jmeter if控制器使用
if控制器有两种用法 1.不勾选“interpret condition as variable expression” 直接输入我们需要判断的表达式即可,判断表达式为真时,执行if控制器下的请求 2 ...
- css: scroll-table
.scroll-table { table tbody { display: block; max-height: 120px; overflow-y: scroll; } table thead,t ...