我是python中的新手,我有多个选项,例如1到99,我想在按下f2后选择23作为窗口我按2和3然后按回车,23号被选中。我想在ubuntu 10.04中这样做。什么程序?我正在写一些代码
def keyDown(self,e):
if e.keystring == "f2":
selectedNumber = 0
elif e.keystring == "enter":
print selectedNumber
selectedNumber =0
else:
selectedNumber +=int(e.keystring)
提前致谢
答案 0 :(得分:0)
您可以将所选数字存储为字符串,按Enter键时将数字转换为int。需要更多的输入验证,但这应该给你一个想法。
def keyDown(self,e):
if e.keystring == "f2":
selectedNumber = ""
elif e.keystring == "enter":
print int(selectedNumber) # If you are only printing you don't need int()
selectedNumber = ""
else:
selectedNumber += e.keystring