스크립트가 실행되는 동안 로그 라인을 화면에 표시하는 우아한 방법을 찾고 있습니다.병렬 GUI를 사용하여 화면에 로그 라인을 표시
from time import sleep
from threading import Thread
import tkinter as tk
class WaitGuiPrallel(Thread):
def __init__(self, TXT='Wait!', ttl='Logs'):
self.txt = TXT
Thread.__init__(self)
self.ttl = ttl
self.start() # This is starting the self.run()
def run(self):
self.root = tk.Tk()
self.root.attributes("-topmost", True)
self.root.title(self.ttl)
self.label = tk.Label(self.root, text=self.txt, font=("Helvetica", 20))
self.label.pack()
self.Location()
self.root.mainloop()
def Exit(self):
self.root.quit()
def Location(self):
w = 500 # width for the Tk root
h = 150 # height for the Tk root
ws = self.root.winfo_screenwidth() # width of the screen
self.root.geometry('%dx%d+%d+%d' % (w, h, ws - w - 20, 10))
def Update(self, newText):
self.txt1 = newText
self.label.destroy()
self.label = tk.Label(self.root, text=self.txt1,
font=("Helvetica", 12))
self.label.pack()
self.root.update()
Wait = WaitGuiPrallel(TXT='Wait! Do not touch mouse or keyboard')
sleep(2)
for t in range(5):
sleep(1)
Wait.Update(newText='Log line %s' % t)
Wait.Update(newText='Done!')
sleep(1)
Wait.Exit()
현재 스크립트는 몇 가지 문제가 있어요 : 그것은 우아한되지 않습니다
을 - 다른 스레드에서 업데이트 할 때이 문제가 더 나은 방법
이 있어야
Spyder + IPython에서 두 번 실행하는 것은 불가능합니다 (IPython 동결)
2 개의 창을 동시에 열어 보시겠습니까? 쓰레드는 잊어 버리십시오. 두 번째 윈도우를 만들기 위해'tk.Topvel'을 사용하십시오. – Novel