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

yipeiwu_com5年前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设计】。

相关文章

windows下pycharm安装、创建文件、配置默认模板

windows下pycharm安装、创建文件、配置默认模板

本文为大家分享了windows下pycharm安装、创建文件、配置默认模板的具体步骤,供大家参考,具体内容如下 步骤: 下包 —->安装——>创建文件—->定制模板...

浅谈Python中的作用域规则和闭包

在对Python中的闭包进行简单分析之前,我们先了解一下Python中的作用域规则。关于Python中作用域的详细知识,有很多的博文都进行了介绍。这里我们先从一个简单的例子入手。 Pyt...

小结Python用fork来创建子进程注意事项

自己随手写了Python下 fork 进程的测试代码(来说明这个问题不一定完全合适): def fork(a): def now(): import datetime re...

深入Python解释器理解Python中的字节码

深入Python解释器理解Python中的字节码

我最近在参与Python字节码相关的工作,想与大家分享一些这方面的经验。更准确的说,我正在参与2.6到2.7版本的CPython解释器字节码的工作。 Python是一门动态语言,在命令行...

Python中decorator使用实例

在我以前介绍 Python 2.4 特性的Blog中已经介绍过了decorator了,不过,那时是照猫画虎,现在再仔细描述一下它的使用。 关于decorator的详细介绍在 Python...