当我使用系统("暂停")时,屏幕上会出现一行"按任意键继续...".
这是一种冥想,使阅读输出相当麻烦.
有没有办法阻止它的到来?
目标
我正在尝试编写一个基本文件,我可以在所有其他程序中导入,这些程序将具有一个简单的功能,将从用户输入然后返回它.
码
为此,我有以下代码:
class takeInput(object):
def __init__(self,requestMessage,parent):
self.string = ''
self.frame = Frame(parent)
self.frame.pack()
self.acceptInput(requestMessage)
def acceptInput(self,requestMessage):
r = self.frame
k = Label(r,text=requestMessage)
k.pack(side='left')
self.e = Entry(r,text='Name')
self.e.pack(side='left')
self.e.focus_set()
b = Button(r,text='okay',command=self.gettext)
b.pack(side='right')
def gettext(self):
self.string = self.e.get()
self.frame.destroy()
print self.string
def getString(self):
return self.string
def getText(requestMessage,parent):
global a
a = takeInput(requestMessage,parent)
return a.getString()
Run Code Online (Sandbox Code Playgroud)
我还添加了一些脚本级代码,以便测试:
root = Tk()
getText('enter your name',root)
var = a.getString()
print var
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
真令我困惑的是:
var 没有我输入的值有空字符串 ''a.string 变量具有我输入的值,我从shell中检查了它.还当我试图从分配返回的字符串a.getString(),以var在shell,然后它的工作. …
我正在写一个循环,如果一个队列不为空,循环将运行,我只是想知道是否需要break在循环结束时包含一个.基本上每个循环应该为队列中的每个元素运行,直到队列为空.
那应该是以下哪一项 - 我只是不知道是否有正确的事情要做.
while (1)
{
/*process message from incoming queue*/
if (!msgs_inc.empty())
{
/*categorise incoming message into global map of outgoing messages*/
msgInfo current_msg = incMsgClassification(msgs_inc.front());
msgs_inc.pop();
clients_msg[current_msg.destID][current_msg.priorityLevel].push(current_msg);
}
}
Run Code Online (Sandbox Code Playgroud)
要么
while (1)
{
//Sleep(50000);
//cout << "success" << endl;
/*process message from incoming queue*/
if (!msgs_inc.empty())
{
/*categorise incoming message into global map of outgoing messages*/
msgInfo current_msg = incMsgClassification(msgs_inc.front());
msgs_inc.pop();
clients_msg[current_msg.destID][current_msg.priorityLevel].push(current_msg);
break;
}
}
Run Code Online (Sandbox Code Playgroud) 问题
我正在为一个简单的秒表编写代码.在每三次运行之后,清除帧并在同一窗口中启动新会话.时间被写入文件.但在清除屏幕之前,我希望用户查看所用的时间,然后清除屏幕.
目标
等待按键,这样我们就可以破坏帧并在此之后打印一些新文本.
我检查了什么
http://www.daniweb.com/software-development/python/code/216830/tkinter-keypress-event-python
这不是很有用,因为正在打印密钥.
条件
我不关心密钥是什么,除非它是以下某些东西:
['e','s','r']
如果没有打开按键,那么我可以继续清除屏幕.这些密钥用于程序中的某些其他特定目的.
请帮我一个方法来做到这一点.
我有两个清单:
dict可选的键
这简直让我发疯.
这就是发生的事情:
在python shell里面:
>>> from Crypto.Cipher import ARC4
>>> a = ARC4.new('0123456789123456')
>>> b = ARC4.new('0123456789123456')
>>> de = b.decrypt
>>> en = a.encrypt
>>> en('abcd')
'\x18\x07\x8a\xdc'
>>> en('abcd')
'\x89>\xa0T'
>>> en('abcd')
'y\xe1-\xfe'
>>> en('abcd')
'\xc7\xf6\x19\xfc'
>>>
Run Code Online (Sandbox Code Playgroud)
我abcd用相同的密钥加密了4次.四次我得到了不同的加密字符串.
当我做了以下事情时(也许我会在解密所有上述不同的加密消息时获得相同的解密消息).
>>> al = []
>>> for i in range(10):
al.append(en('abcd'))
>>> al
['\x81\x05h\x06', '\x11;\x88\xc7', '\xb6\xb9g\x10', '\x1e$\x8c\xca', '\xbdh\xc2\xf0', 'ruiO', '7\xec\x7f\xdf', '\x08\xf3\x90\x8a', '\x1c\x95\xf3(', '\xbd@-\x11']
>>> gl = []
>>> for i in range(10):
gl.append(de(al[i]))
>>> gl
['\xc8\x0f6\xb7', '\x18y`A', 'tm\x12\t', '\x9c\xf65M', …Run Code Online (Sandbox Code Playgroud) 这是一个有三位数的游戏Cows and Bulls的模拟
我试图得到两个数字之间的牛和公牛数量.其中一个是由计算机生成的,另一个是由用户猜测的.我已经解析了我拥有的两个数字,现在我有两个列表,每个列表包含三个元素,每个元素都是数字中的一个数字.所以:
237将列出清单[2,3,7].并且我确保保持相对指数(hundreds, tens, units).一般模式是:.
这两个列表存储在两个列表中:machine和person.
所以,我写了下面的代码,最直观的算法:
cows并bulls在此循环开始之前初始化为0.
for x in person:
if x in machine:
if machine.index(x) == person.index(x):
bulls += 1
print x,' in correct place'
else:
print x,' in wrong place'
cows += 1
Run Code Online (Sandbox Code Playgroud)
我开始使用计算机猜测的不同类型的数字来测试它.
很随意,我决定277.我猜测447.这里,我得到了第一个线索,这个算法可能无法正常工作.我有1头牛和0头公牛.而我应该有1头牛和1头牛.
这是第一个算法的输出表:
Guess Output Expected Output
447 0 bull, 1 cow 1 bull, 0 cow
477 2 bulls, 0 cows 2 bulls, 0 cows …Run Code Online (Sandbox Code Playgroud)