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. 这口号是当年心目中的产品方向,接着就朝这个方向慢慢打 ...
随机推荐
- 【翻译】Java Array的排名前十方法(Top 10 Methods for Java Arrays)
这里列举了Java Array 的前十的方法.他们在stackoverflow最大投票的问题. The following are top 10 methods for Java Array. The ...
- Java读源码之ReentrantLock(2)
前言 本文是 ReentrantLock 源码的第二篇,第一篇主要介绍了公平锁非公平锁正常的加锁解锁流程,虽然表达能力有限不知道有没有讲清楚,本着不太监的原则,本文填补下第一篇中挖的坑. Java读源 ...
- re模块语法—python正则表达式
用字符串匹配实现 对于简单的匹配查找,可以通过字符串匹配实现,比如:查找以”hello”开头的字符串 此时就可以正确查找出以start开始的字符串了 python中的正则表达式模块 在python中为 ...
- G - Messy codeforces1262C
题目大意: 输入n和m,n是n个字符,m是m个前缀.对前缀的规定可以配对的括号.比如(),,((()))等等.在输入n个括号字符,对这个n个字符,通过交换使其满足m个前缀.交换次数不限,规则想当与re ...
- 利用Putty建立SSH的tunnels访问内网资源
适用场景访问阿里或者腾讯云只针对内网开放的资源. 本文以SQLSERVER 举例 举例你的内网 SQLSERVER的访问地址是192.168.33.88 . 你的Microsoft SQL Serve ...
- Java IO 流 -- 数据流和对象流 DataOutputStream ObjectOutputStream
DataOutputStream 和 ObjectOutputStream的共同点是: 1.写出后读取 2.读取顺序和写出一致 数据流操作: // 写入 ByteArrayOutputStream b ...
- jQuery的attr和prop属性
<div id="div1"></div> attr: 首先是一个参数的attr. $("#div").attr("id&qu ...
- socket小计
socket,是一个实现了双向通信的链接. 将http比喻为轿车,承载数据.传递数据,那么socket,就是轿车的发动机,它轿车动起来.
- ES6中的let关键字,有什么用呢?
来吧,开始本节的学习! ES6 给开发者带来很多令人激动的特性,其中let关键字就是其中之一. 那么,let关键字是什么东西? let 的用途 我们回想一下,我们平时在写代码的时候,用var来声明一个 ...
- thinkphp--多个id查询
$feedback_list = $feedback -> where( array("member_id"=>array("in", " ...