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实现html转ubb代码(html2ubb)
Jul 03 Python
Python中用PIL库批量给图片加上序号的教程
May 06 Python
Python 爬虫模拟登陆知乎
Sep 23 Python
python将unicode转为str的方法
Jun 21 Python
Python编程产生非均匀随机数的几种方法代码分享
Dec 13 Python
使用Python的toolz库开始函数式编程的方法
Nov 15 Python
python 使用while写猜年龄小游戏过程解析
Oct 07 Python
pytorch: Parameter 的数据结构实例
Dec 31 Python
Python多重继承之菱形继承的实例详解
Feb 12 Python
详解在Python中使用Torchmoji将文本转换为表情符号
Jul 27 Python
python识别验证码的思路及解决方案
Sep 13 Python
python 根据列表批量下载网易云音乐的免费音乐
Dec 03 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
在IIS7.0下面配置PHP 5.3.2运行环境的方法
2010/04/13 PHP
mysql总结之explain
2012/02/27 PHP
PHP生成唯一订单号
2015/07/05 PHP
PHP如何将log信息写入服务器中的log文件
2015/07/29 PHP
PHP实现websocket通信的方法示例
2018/08/28 PHP
PHP使用递归按层级查找数据的方法
2019/11/10 PHP
基于jQuery实现复选框的全选 全不选 反选功能
2014/11/24 Javascript
JS实现n秒后自动跳转的两种方法
2020/11/30 Javascript
深入解析桶排序算法及Node.js上JavaScript的代码实现
2016/07/06 Javascript
Angular.JS中的this指向详解
2017/05/17 Javascript
JavaScript之Map和Set_动力节点Java学院整理
2017/06/29 Javascript
Koa从零搭建到Api实现项目的搭建方法
2019/07/30 Javascript
解决layer 动态加载select 失效的问题
2019/09/18 Javascript
vue新建项目并配置标准路由过程解析
2019/12/09 Javascript
有趣的JavaScript隐式类型转换操作实例分析
2020/05/02 Javascript
布同 统计英文单词的个数的python代码
2011/03/13 Python
编写同时兼容Python2.x与Python3.x版本的代码的几个示例
2015/03/30 Python
python递归全排列实现方法
2018/08/18 Python
python读取txt文件并取其某一列数据的示例
2019/02/19 Python
pytorch掉坑记录:model.eval的作用说明
2020/06/23 Python
CSS3中box-shadow的用法介绍
2015/07/15 HTML / CSS
欧缇丽美国官网:Caudalie美国
2016/12/31 全球购物
美国医疗用品、医疗设备和家庭保健用品商店:Medical Supply Depot
2018/07/08 全球购物
给排水工程师岗位职责
2013/11/21 职场文书
物理教师自荐信范文
2013/12/28 职场文书
出纳员岗位职责
2014/03/13 职场文书
学习经验演讲稿
2014/05/10 职场文书
法律专业自荐信
2014/06/03 职场文书
欢迎新生标语
2014/10/06 职场文书
秋冬农业生产标语
2014/10/09 职场文书
2015政治思想表现评语
2015/03/25 职场文书
致运动员加油稿
2015/07/21 职场文书
python文件名批量重命名脚本实例代码
2021/04/22 Python
Python数据清洗工具之Numpy的基本操作
2021/04/22 Python
Python进行区间取值案例讲解
2021/08/02 Python
python中mongodb包操作数据库
2022/04/19 Python