Python-Tkinter Text输入内容在界面显示的实例

yipeiwu_com6年前Python基础

使用Tkinter(py2.7)text文本框中输入内容在界面中显示–较为规整的代码:

import Tkinter as tk

class Window:
	def __init__(self,handle):
		self.win = handle
		self.createwindow()
		self.run()
		
	def createwindow(self):
		self.win.geometry('400x400')
		#label 1
		self.label_text = tk.StringVar()
		self.label_text.set("----")
		self.lable = tk.Label(self.win,
					textvariable=self.label_text,
					font=('Arial',11),width=15,height=2)
		self.lable.pack()

		#text_contrl
		self.entry_text = tk.StringVar()
		self.entry = tk.Entry(self.win,textvariable=self.entry_text,width=30)
		self.entry.pack()

		#button
		self.button =tk.Button(self.win,text="set label to text",width=15,height=2,command=self.setlabel)
		self.button.pack()

	def setlabel(self):
		print(self.entry_text.get())
		self.label_text.set(self.entry_text.get())

	def run(self):
		try:
			self.win.mainloop()
		except Exception as e:
			print ("*** exception:\n".format(e))
def main():
			window = tk.Tk()
			window.title('hello tkinter')
			Window(window).run()
if __name__ == "__main__":
	main()

以上这篇Python-Tkinter Text输入内容在界面显示的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python实现的视频播放器功能完整示例

本文实例讲述了Python实现的视频播放器功能。分享给大家供大家参考,具体如下: # -*- coding:utf-8 -*- #! python3 # --------------...

使用Python解析JSON数据的基本方法

Python的json模块提供了一种很简单的方式来编码和解码JSON数据。 其中两个主要的函数是 json.dumps() 和 json.loads() , 要比其他序列化函数库如pic...

Python实现LRU算法的2种方法

LRU:least recently used,最近最少使用算法。它的使用场景是:在有限的空间中存储对象时,当空间满时,会按一定的原则删除原有的对象,常用的原则(算法)有LRU,FIFO...

Python错误提示:[Errno 24] Too many open files的分析与解决

背景 最近在工作中发现了一个错误,在执行多线程扫描脚本的时候频繁出现下面这个错误 HTTPConnectionPool(host=‘t.tips', port=80): Max re...

CentOS7下python3.7.0安装教程

记录了CentOS7 安装python3.7.0的详细过程,供大家参考,具体内容如下 1.下载及解压 python3.7的安装包可从官网下载上传到主机,也可以用wget直接下载。 [...