Python Get Key press
refer from: http://www.daniweb.com/forums/thread115282.html#
python
Syntax
(Toggle Plain Text
)
# respond to a key
without the need to press
enter
import
Tkinter
as tk
def
keypress(
event)
:
if
event.keysym
== 'Escape'
:
root.destroy
(
)
x = event.char
if
x == "w"
:
print
"blaw blaw blaw"
elif
x == "a"
:
print
"blaha blaha blaha"
elif
x == "s"
:
print
"blash blash blash"
elif
x == "d"
:
print
"blad blad blad"
else
:
print
x
root = tk.Tk
(
)
print
"Press
a key
(Escape key
to exit):"
root.bind_all
(
'<Key
>'
, keypress)
# don't show the tk window
root.withdraw
(
)
root.mainloop
(
)
相关文档:
import urllib
from HTMLParser import HTMLParser
class TitleParser(HTMLParser):
def __init__(self):
self.title = ''
self.divcontent = ''
self.readingtitle = 0
self.readingdiv = 0
HTMLParser.__init__(self)
def handle_starttag(self, tag, attrs):
......
万恶的编码
小菜对于老师上一节讲的不是很明白,因为没有一本书是将文件与web一起讲授的,他决定自己探究一下它们之间的不同:
首先,小菜在C盘建了一个文本文档 file.txt,输入四个字:我是小菜。
然后,小菜在shell中练习起来:
>>> file=open("c:\\file.txt","r")
>>> data=file.read()
>> ......
Install Python Eric IDE
1 Download following things
1) Python3.1
2) PyQt for python 3.1
(http://www.riverbankcomputing.co.uk/software/pyqt/download) I am using
PyQt-Py3.1-gpl-4.7.3-2.exe
3) Eric5 IDE
(http://eric-ide.python-projects.org/eric-download.html)
2 ......
前言:
最近又想学习python,又想去温习一下算法,于是就想出了这个两不误的方法,^_^
堆栈:
使用python的列表结构,详情可以查看help(list)
#Filename: stack.py
shoplist=['apple','mango','carrot','banana']
shoplist.append('rice')
popitem=shoplist[-1]
del shoplist[-1]
print 'the popitem is',popitem
......
list.append(item)
list.extend(sequence)
http://docs.python.org/tutorial/datastructures.html
http://docs.python.org/library/functions.html 这几天看一下
python howto
恩。python documentation 确实很好很强大啊!
list.append(x)Add an item to the end of the list; equivalent to a[len(a):]&n ......