2

GUI consists one Run Button which should run the first program as many times user wants & display output in tkinter text.

My code(2nd .py file):

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()

I want Output of 1st program which is random every time in "tkinter text of another (2nd program) instead of quote lines mentioned in above code.

Stevo Mitric
  • 1,279
  • 13
  • 17
  • There's not nearly enough information in the question, and you've shown no effort towards solving the problem yourself. – Bryan Oakley Sep 05 '16 at 17:21
  • The code isn't properly formatted, and the question mentions two programs but I only see one. – Bryan Oakley Sep 05 '16 at 18:25
  • @BryanOakley Can't show first program.. as it is part of my project. I am new to python & stackoverflow both. In learning phase. Hope you got my question, please update with helpfull answer if possible. :| – SUMIT SATAM Sep 05 '16 at 18:31

1 Answers1

1

Output first program to txt file.

Read from that txt file into the tkinter GUI by checking when it was last modified so as to avoid mutex issues.

Therefore:

# 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)
Mixone
  • 1,152
  • 1
  • 12
  • 22