GUIは、ユーザーが望む回数だけ最初のプログラムを実行し、tkinterテキストで出力を表示する1つの実行ボタンで構成されています。
私のコード(2番目の.pyファイル):
from tkinter import*
from tkinter import ttk
import Random Game
root = Tk()
root.title("Random Game 1.0")
quote = "Long \nRandom \nText \nGenerated \nBy \nRandom Function \nAnd \nControl Structures"
frame = Frame(root)
labelText = StringVar()
label = Label(frame, textvariable=labelText).pack()
button = Button(frame, text="Click to Run").pack()
labelText.set("Random Game 1.0")
Label(root, text ="")
T = Text(root)
frame.pack()
T.pack()
T.insert(END, quote)
root.mainloop()
上記のコードで言及されている引用行の代わりに、「別の(2番目のプログラム)のtkinterテキストで毎回ランダムな1番目のプログラムの出力が必要です。
最初のプログラムをtxtファイルに出力します。
ミューテックスの問題を回避するために、最後に変更された日時を確認して、そのtxtファイルからtkinterGUIに読み込みます。
したがって:
# Prog 1:
file = open("log.txt", "w")
# code that writes there
# Prog 2:
file = open("log.txt", "r")
# use data to show in the tkinter with its mainloop for example
# in mainloop()...
# .....
if other_prog_has_written_something_new :
data = file.readlines()
useDataInGUI(data)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加