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 读取excel文件生成sql文件实例详解

python 读取excel文件生成sql文件实例详解 学了python这么久,总算是在工作中用到一次。这次是为了从excel文件中读取数据然后写入到数据库中。这个逻辑用java来写的话...

Python如何为图片添加水印

Python如何为图片添加水印

添加水印的主要目的是为了版权保护,使自己的图像不被抄袭或者恶意转载。网上有很多制作水印的工具,本帖介绍怎么使用Python-Pillow库给图片添加水印。 使用ImageMagick添加...

Python重新加载模块的实现方法

importlib 模块的作用 模块,是一个一个单独的py文件 包,里面包含多个模块(py文件) 动态导入模块,这样就不用写那么多的import代码, 典型的例子: 自动同步服务,每个网...

Python类和对象的定义与实际应用案例分析

Python类和对象的定义与实际应用案例分析

本文实例讲述了Python类和对象的定义与实际应用。分享给大家供大家参考,具体如下: 1.DVD管理系统 # -*- coding:utf-8 -*- #! python3 clas...

python中import与from方法总结(推荐)

一、模块&包简介 模块:所谓模块就是一个.py文件,用来存放变量,方法的文件,便于在其他python文件中导入(通过import或from)。 包(package): 包是更大的组织单位...