范宇文,塘沽洗头房,蔡洪赴洛
本文实例讲述了python使用tkinter库实现文本显示用户输入功能。分享给大家供大家参考,具体如下:
#coding:utf-8 from tkinter import * class app: def __init__(self,root): #定义帧 frame = frame(root) frame.pack() self.frame = frame w = label(frame,text = "calculator") w.pack() self.newinput() #调用回调函数 button1 = button(frame,text='1',fg="red",command = lambda : self.buttoncb(1)) button1.pack() button2 = button(frame,text='2',fg="red",command = lambda : self.buttoncb(2)) button2.pack() button = button(frame,text='quit',fg="red",command = root.quit) button.pack() def newinput(self): v = stringvar() e = entry(self.frame,textvariable = v) self.v = v e.pack() #定义回调函数 def buttoncb(self,i): #print "button" val = self.v.get() self.v.set(val+str(i)) root=tk() a = app(root) root.mainloop()
运行结果:
更多关于python相关内容感兴趣的读者可查看本站专题:《python数据结构与算法教程》、《python函数使用技巧总结》、《python字符串操作技巧汇总》、《python入门与进阶经典教程》及《python文件与目录操作技巧汇总》
希望本文所述对大家python程序设计有所帮助。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
python求numpy中array按列非零元素的平均值案例
网友评论