1
파이썬 쉘의 출력을 텍스트 상자가있는 Tkinter GUI로 리디렉션하고 싶습니다.파이썬에서 출력을위한 텍스트 박스 (텍스트 기반 게임)
예를 들어 내 게임의 인벤토리를 클릭하면 파이썬 껍질에 소모품이 표시됩니다. GUI 텍스트 상자에 표시되도록하고 싶습니다.
어떻게해야합니까?
class textbox_handler:
def __init__(self, text):
self.data = []
self.text = text #text is your tk text widget.
def write(self, s):
self.data.append(s)
def print_out(self):
for line in data:
self.text.insert('end',line)
그런 다음 주요 기능에 :
import sys
def main():
handler = textbox_handler(text1)
sys.stdout = handler
print "sample text."
print "sample text #2."
print "another sample text."
#or you can use without setting sys.stdout
print >>handler, "yet another sample text."
각 인쇄 문 호출 핸들러 객체의 메소드를 작성
일부 코드를 보여줍니다. 쉘에서 * 또는 *로 리디렉션하는 것에 대해 이야기하는 것은 분명하지 않습니다. – joaquin