zoukankan      html  css  js  c++  java
  • tkinter计算字符串的值 分类: python 小练习 python 2013-06-30 17:11 299人阅读 评论(0) 收藏


    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()

            button3 = Button(frame,text='+',fg="red",command = lambda : self.buttoncb("+"))
            button3.pack()

            button4 = Button(frame,text='=',fg="red",command = lambda : self.cal())
            button4.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):
            val = self.v.get()
            self.v.set(val+str(i))

        def cal(self):
            v = self.v.get()

            self.v.set(eval(v))


    root = Tk()
    a = App(root)
    root.mainloop()

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    网站迁移服务器后CPU、内存飙升,设置robots.txt 问题
    System.Web.Mvc 找到的程序集清单定义与程序集引用不匹配
    滑动窗口协议
    TCP拥塞控制
    计网常用协议
    TCP协议中的三次握手、四次挥手
    浏览网页的详细过程
    docker网络模式
    openstack网络
    查找算法
  • 原文地址:https://www.cnblogs.com/think1988/p/4628139.html
Copyright © 2011-2022 走看看