网络编程
位置:首页>> 网络编程>> Python编程>> Python使用tkinter库实现文本显示用户输入功能示例

Python使用tkinter库实现文本显示用户输入功能示例

作者:my2010sam  发布时间:2023-09-21 11:00:17 

标签:Python,tkinter

本文实例讲述了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使用tkinter库实现文本显示用户输入功能示例

希望本文所述对大家Python程序设计有所帮助。

来源:https://blog.csdn.net/my2010sam/article/details/9208253

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com