당신이 (something with an event loop를) GUI를 사용할 수있는 입력을 기다리는 동시에 어떤 임의의 출력을 표시 :
#!/usr/bin/env python3
import random
from tkinter import E, END, N, S, scrolledtext, Tk, ttk, W
class App:
password = "123456" # the most common password
def __init__(self, master):
self.master = master
self.master.title('To stop, type: ' + self.password)
# content frame (padding, etc)
frame = ttk.Frame(master, padding="3 3 3 3")
frame.grid(column=0, row=0, sticky=(N, W, E, S))
# an area where random messages to appear
self.textarea = scrolledtext.ScrolledText(frame)
# an area where the password to be typed
textfield = ttk.Entry(frame)
# put one on top of the other
self.textarea.grid(row=0)
textfield.grid(row=1, sticky=(E, W))
textfield.bind('<KeyRelease>', self.check_password)
textfield.focus() # put cursor into the entry
self.update_textarea()
def update_textarea(self):
# insert random Unicode codepoint in U+0000-U+FFFF range
character = chr(random.choice(range(0xffff)))
self.textarea.configure(state='normal') # enable insert
self.textarea.insert(END, character)
self.textarea.configure(state='disabled') # disable editing
self.master.after(10, self.update_textarea) # in 10 milliseconds
def check_password(self, event):
if self.password in event.widget.get():
self.master.destroy() # exit GUI
App(Tk()).master.mainloop()
출처
2014-09-10 15:54:07
jfs
GUI 작성을 고려 했습니까? 입력을위한 텍스트 필드와 출력을위한 텍스트 영역은 무엇입니까? – jfs
나는 결국 GUI를 만들 예정이다. 하지만이게 내 문제를 해결할 수 있을까? – user2456977
GUI는 일반적으로 이벤트 루프를 사용하여 일을 동시에 처리하는 등 간단한 작업을 수행합니다. 예를 들어 텍스트 필드가 입력 대기하는 동안 텍스트 영역에 임의의 숫자를 채우는 함수를 반복적으로 호출합니다. – jfs