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多进程读图提取特征存npy

本文实例为大家分享了python多进程读图提取特征存npy的具体代码,供大家参考,具体内容如下 import multiprocessing import os, time, ran...

python微信跳一跳系列之自动计算跳一跳距离

python微信跳一跳系列之自动计算跳一跳距离

到现在为止,我们通过前面几篇博文的描述和分析,已经可以自动实现棋子、棋盘位置的准确判断,计算一下两个中心点之间的距离,并绘制在图形上,效果如下。 效果 图中的棋子定位采用HSV颜色识别...

Python操作SQLite数据库的方法详解

本文实例讲述了Python操作SQLite数据库的方法。分享给大家供大家参考,具体如下: SQLite简单介绍 SQLite数据库是一款非常小巧的嵌入式开源数据库软件,也就是说没有独立的...

python 利用pandas将arff文件转csv文件的方法

直接贴代码啦: #coding=utf-8 import pandas as pd def arff_to_csv(fpath): #读取arff数据 if fpath.f...

常见的在Python中实现单例模式的三种方法

单例模式是一种常用的软件设计模式。在它的核心结构中只包含一个被称为单例类的特殊类。通过单例模式可以保证系统中一个类只有一个实例而且该实例易于外界访问,从而方便对实例个数的控制并节约系统资...