易截截图软件、单文件、免安装、纯绿色、仅160KB

Python: python的简单表达式计算器

这是一个简单的表达式计算器, 不太懂用Tkinter写GUI, 参考了别人的代码
from __future__ import division
from Tkinter import Tk, Entry, Button, Label, mainloop
from tkFont import Font
def get_value ():
v = ''
try:
v = eval(text.get()) #use eval to calculate the vlaue of the text
except:
pass
if isinstance(v, (int, float, long)):
pass
else:
v = 'Error...'
label.config(text = v) #use config to change the text


top = Tk()
top.title("calculator")
ft = Font(family = 'Courier New', size = 12)
text = Entry(top, font = ft)
button = Button(top, text = 'Ok', command = get_value)
label = Label(text = '(+ - * / % **)', font = ft)
Enter = lambda x: x.keycode == 13 and get_value()
Key = lambda x: label.config(text = '(+ - * / % **)')
text.bind('<Key>', Enter) #when the key is enter, execute the function Enter
text.focus()
text.bind('<Button-1>', Key) #when click the left-key, execute the function Key
text.pack()
button.pack()
label.pack()
mainloop()


相关文档:

Python性能测试函数

Python 社区有句俗语:“Python 自己带着电池。” 别自己写计时框架。Python 2.3以后 、具备一个叫做 timeit 的完美计时工具。DiveInto中的例子
>>> import timeit
>>> t = timeit.Timer("soundex.soundex('Pilgrim')",
... "import soundex")
>>> t.timeit() ......

用python连接mysql数据库


#
-*- encoding: gb2312 -*-
import
os, sys, string
import
MySQLdb
#
连接数据库
try
:
conn
=
MySQLdb.connect(host
=
'
localhost
'
,user
=
'
root
'
,passwd
=
'
xxxx
'
,db
=
'
test1
'
)
except
Exception, e:
print
e
sys.exit()
......

用python, c#, java写的文件拷贝

     前一段时间试着用这三种语言简单的写了关于文件拷贝的程序,发现c#和python的api惊人的相似,对于文件的操作这两种语言非常的方便。都没有加异常的处理
C#源代码:
        public static void CopyFile(string source, string destination)
  & ......

[Python module] multiprocessing


multiprocessing — Process-based “threading” interface
Introduction
multiprocessing is a package that supports spawning processes using an API similar to the threading module. The multiprocessing package offers both local and remote concurrency, effectively side-stepping the Glo ......

写了几个有关operaminimod的python小程序

写了几个有关operaminimod的python小程序
firefox->opm书签转换
import re
def pipeiwangzhi(a):
    s=[]
    pp= re.compile(r'<DT><A HREF="(.*)" ADD_DATE=(.*>)(.*)</A>')
    m=pp.search(a)
    s1=[]
  ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号