내가 아는 한, raw_input은 python 명령 콘솔에서 입력을 받아들이 기 때문에 이것은 불가능합니다. 그러나 예상치 못한 주위를 둘러 쌀 수있는 몇 가지 방법이 있습니다.
1 - 콘솔을 사용하는 대신 출력 및 입력 줄이있는 간단한 Tkinter 창을 만듭니다. 고정 폭 글꼴을 사용하는 스크롤 막대에있을 수있는 창 텍스트 끝에 메시지를 추가하는 사용자 지정 인쇄 기능을 만든 다음 입력에 응답하는 명령 프롬프트 상자를 만듭니다. 그 코드는 다음과 같이 보일 것입니다 :
from Tkinter import *
root = Tk()
topframe=Frame(root)
bottomframe=Frame(root)
bottomframe.pack(side=BOTTOM,fill=X)
topframe.pack(side=TOP,fill=BOTH)
scrollbar = Scrollbar(topframe)
scrollbar.pack(side=RIGHT,fill=Y)
text = Text(topframe,yscrollcommand=scrollbar.set)
text.pack(side=LEFT,fill=BOTH)
scrollbar.config(command=text.yview)
text.config(state=DISABLED)
v = StringVar()
e = Entry(bottomframe,textvariable=v)
def submit():
command = v.get()
v.set('')
#your input handling code goes here.
wprint(command)
#end your input handling
e.bind('<Return>',submit)
button=Button(bottomframe,text='RUN',command=submit)
button.pack(side=RIGHT)
e.pack(expand=True,side=LEFT,fill=X)
def wprint(obj):
text.config(state=NORMAL)
text.insert(END,str(obj)+'\n')
text.config(state=DISABLED)
root.mainloop()
또 다른 옵션은 다음과 같이보고 자신의 인쇄 및 raw_input을 방법을 생성하는 것입니다 : 왜 당신이 GUI 프레임 워크를 사용하지 않는
import threading
wlock=threading.Lock()
printqueue=[]
rinput=False
def winput(text):
with wlock:
global printqueue,rinput
rinput=True
text = raw_input(text)
rinput=False
for text in printqueue:
print(text)
printqueue=[]
return text
def wprint(obj):
global printqueue
if not(rinput):
print(str(obj))
else:
printqueue.append(str(obj))
을 이런 종류의 일을 위해서? –