python图形用户接口实例详解


Posted in Python onDecember 16, 2019

本文实例为大家分享了python图形用户接口实例的具体代码,供大家参考,具体内容如下

运用tkinter图形库,模拟聊天应用界面,实现信息发送.

from tkinter import *
import time
 
def main():
 #发送消息
 def sendMsg():
 strMsg = '我:'+ time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+'\n'
 txtMsglist.insert(END,strMsg,'greencolor')
 txtMsglist.insert(END,txtMsg.get('0.0', END))
 txtMsg.delete('0.0',END)
 #键盘发送消息
 def senMsgKeyboard(event):
 if event.keysym == "Up":
  sendMsg()
 #取消发送
 def cancelMsg():
 txtMsg.delete('0.0', END)
 #窗口定义
 t = Tk()
 t.title("聊天窗口")
 
 # 页面布局
 # 创建frame容器
 frmLT = Frame(width=500, height=320, bg='white')
 frmLC = Frame(width=500, height=150, bg='white')
 frmLB = Frame(width=500, height=30)
 frmRT = Frame(width=200,height=500)
 # 创建控件
 txtMsglist = Text(frmLT)
 txtMsglist.tag_config('greencolor', foreground='#008C00')
 txtMsg = Text(frmLC)
 # 键盘发送消息
 txtMsg.bind("<KeyPress-Up>", senMsgKeyboard)
 # 按钮发送消息
 btnSend = Button(frmLB, text='发送', width=8, command=sendMsg)
 btnCancel = Button(frmLB, text='取消', width=8, command=cancelMsg)
 imageLink = PhotoImage(file = "test.gif")
 lblImage = Label(frmRT, image=imageLink)
 #控件布置到页面
 frmLT.grid(row=0, column=0, columnspan=2, padx=1, pady=3)
 frmLC.grid(row=1, column=0, columnspan=2, padx=1, pady=3)
 frmLB.grid(row=2, column=0, columnspan=2)
 frmRT.grid(row=0, column=2, rowspan=3, padx=2, pady=3)
 # 固定大小
 frmLT.grid_propagate(0)
 frmLC.grid_propagate(0)
 frmLB.grid_propagate(0)
 frmRT.grid_propagate(0)
 
 btnSend.grid(row=2, column=0)
 btnCancel.grid(row=2, column=1)
 lblImage.grid()
 txtMsglist.grid()
 txtMsg.grid()
 
 # 主事件循环
 t.mainloop()
if __name__ == '__main__':
 main()

界面效果如下:

python图形用户接口实例详解

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python中使用select模块实现非阻塞的IO
Feb 03 Python
浅谈Python数据类型判断及列表脚本操作
Nov 04 Python
Anaconda多环境多版本python配置操作方法
Sep 12 Python
Python和Java进行DES加密和解密的实例
Jan 09 Python
Python模拟登录的多种方法(四种)
Jun 01 Python
Python定义一个跨越多行的字符串的多种方法小结
Jul 19 Python
PyQt打开保存对话框的方法和使用详解
Feb 27 Python
详解Python locals()的陷阱
Mar 26 Python
python实现简单图书管理系统
Nov 22 Python
numpy ndarray 按条件筛选数组,关联筛选的例子
Nov 26 Python
4行Python代码生成图像验证码(2种)
Apr 07 Python
python实现自动清理文件夹旧文件
May 10 Python
Python实现微信好友的数据分析
Dec 16 #Python
Python字典中的值为列表或字典的构造实例
Dec 16 #Python
python groupby 函数 as_index详解
Dec 16 #Python
Python基本类型的连接组合和互相转换方式(13种)
Dec 16 #Python
Python实现word2Vec model过程解析
Dec 16 #Python
Python爬虫爬取煎蛋网图片代码实例
Dec 16 #Python
python实现监控阿里云账户余额功能
Dec 16 #Python
You might like
PHP语法速查表
2006/12/06 PHP
让你的网站首页自动选择语言转跳
2006/12/06 PHP
PHP 采集心得技巧
2009/05/15 PHP
php 网页播放器用来播放在线视频的代码(自动判断并选择视频文件类型)
2010/06/03 PHP
在MongoDB中模拟Auto Increment的php代码
2011/03/06 PHP
PHP通过插入mysql数据来实现多机互锁实例
2014/11/05 PHP
PHP实现查询手机归属地的方法详解
2017/04/28 PHP
初学JavaScript_03(ExtJs Grid的简单使用)
2008/10/02 Javascript
用户注册常用javascript代码
2009/08/29 Javascript
基于jquery的大众点评,分类导航实现代码
2011/08/23 Javascript
jquery submit ie6下失效的原因分析及解决方法
2013/11/15 Javascript
jquery简单实现鼠标经过导航条改变背景图
2013/12/17 Javascript
基于jquery实现图片上传本地预览功能
2016/01/08 Javascript
window.onerror()的用法与实例分析
2016/01/27 Javascript
微信小程序开发之实现选项卡(窗口顶部TabBar)页面切换
2016/11/25 Javascript
Angular 项目实现国际化的方法
2018/01/08 Javascript
原生JS实现九宫格抽奖
2020/09/13 Javascript
[03:44]2015国际邀请赛选手档案—Cloud9.NoTail
2015/07/28 DOTA
跟老齐学Python之正规地说一句话
2014/09/28 Python
python实现调用其他python脚本的方法
2014/10/05 Python
numpy中的高维数组转置实例
2018/04/17 Python
浅谈numpy数组中冒号和负号的含义
2018/04/18 Python
Windows系统下PhantomJS的安装和基本用法
2018/10/21 Python
python调用并链接MATLAB脚本详解
2019/07/05 Python
Python如何使用paramiko模块连接linux
2020/03/18 Python
下述程序的作用是计算机数组中的最大元素值及其下标
2012/11/26 面试题
高中生毕业学习总结的自我评价
2013/11/14 职场文书
青年志愿者事迹材料
2014/02/07 职场文书
社会稳定风险评估方案
2014/06/02 职场文书
大学生毕业评语
2014/12/31 职场文书
化验室岗位职责
2015/02/14 职场文书
死亡诗社观后感
2015/06/05 职场文书
四年级数学教学反思
2016/02/16 职场文书
MySQL 十大常用字符串函数详解
2021/06/30 MySQL
Selenium浏览器自动化如何上传文件
2022/04/06 Python
第四次工业革命,打工人与机器人的竞争
2022/04/21 数码科技