Advertisement
robjones90

interpreter_gui

Jun 30th, 2022
1,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.88 KB | None | 0 0
  1. import sys
  2. from tkinter import *
  3. from SC_interpreter import *
  4. import subprocess
  5. import os
  6.  
  7. root=Tk()
  8. root.title('MOD_Python Interpreter')
  9. canvas= Canvas(root, height= 700, width= 800)
  10. canvas.pack()
  11.  
  12.  
  13.  
  14. ## frame
  15. top_frame= Frame(root, bg='#80c1ff', bd=5)
  16. top_frame.place(relx=0.1, rely=0.01, relwidth=0.75, relheight=0.4, anchor='n')
  17.  
  18. background= PhotoImage(file='new402.png')
  19. background_label=Label(root, image=background)
  20. background_label.place(x=0, y=0, relwidth=1, relheight=1)
  21.  
  22. top_frame= Frame(root, bg='#80c1ff', bd=5)
  23. top_frame.place(relx=0.5, rely=0.01, relwidth=0.4, relheight=0.05, anchor='n')
  24. top_label= Label(top_frame, text="Welcome Engineer",font= 30)
  25. top_label.place(relwidth=1, relheight=1)
  26.  
  27. frame= Frame(root, bg='#80c1ff', bd=5)
  28. frame.place(relx=0.5, rely=0.08, relwidth=0.75, relheight=0.4, anchor='n')
  29. ##
  30.  
  31.  
  32. ##
  33. lower_frame= Frame(root, bg='#80c1ff', bd=5)
  34. lower_frame.place(relx=0.5, rely=0.5, relwidth=0.4, relheight=0.4, anchor='n')
  35. lower_label= Label(lower_frame, bg='#80c1ff', bd=5)
  36. lower_label.place(relwidth=1, relheight=1)
  37.  
  38.  
  39. ## textbox input
  40. text_int= Text(frame, font=("Arial", 13 ) )
  41. text_int.place(relx=0.03, rely= 0.05,  relheight=0.4, relwidth=0.65)
  42. ##
  43.  
  44. text_out= Text(lower_frame, font=("Arial", 13 ) )
  45. text_out.place(relx=0.03, rely=0.05,  relheight=0.4, relwidth=0.65)
  46.  
  47.  
  48.  
  49. ## save text
  50. def save_text():
  51.    text_file = open( 'test.txt', 'w')
  52.    text_file.write(text_int.get("1.0",'end-1c'))
  53.    text_file.close()
  54.  
  55. ##
  56.  
  57. ## ospopeopen
  58.  
  59. outputfile = os.popen("python SC_interpreter.py test.txt")
  60. output= outputfile.read()
  61. outputfile.close()
  62.  
  63.  
  64.  
  65. def my_clear():
  66.    text_int.delete(1.0, END)
  67.    input_label.pack_forget()
  68.  
  69.  
  70.  
  71. def my_get():
  72.    global input_label
  73.    global g_data
  74.    g_data= text_int.get("1.0",'end-1c')
  75.    f = open("temp.txt", "w+")
  76.    f.write(g_data)
  77.    f.close()
  78.    process = subprocess.Popen(['python3', 'SC_interpreter.py', 'temp.txt'], shell=False, stdout=subprocess.PIPE)
  79.    subprocess_return = process.stdout.read()
  80.    text_out.insert(END, subprocess_return)
  81.    man = "python" + 'SC_interpreter.py' + g_data
  82.  
  83.    input_label=Label(lower_label, text= output, bg='#80c1ff', bd=5, font=50)
  84.    input_label.pack()
  85.  
  86.  
  87. ## run
  88. button = Button(frame, text= "Run", command= my_get, font=15)
  89. button.place(relx=0.75, rely= 0.7,  relheight=0.1, relwidth=0.2)
  90. ##
  91.  
  92. ##save
  93. button_save = Button(frame, text= "Save", command= save_text, font=15)
  94. button_save.place(relx=0.75, rely= 0.2,  relheight=0.1, relwidth=0.2)
  95.  
  96. ## clear
  97. clear_button = Button(frame, text= "Clear", command=my_clear, font=15)
  98. clear_button.place(relx=0.75, rely= 0.45,  relheight=0.1, relwidth=0.2)
  99. ##
  100. '''
  101. ##
  102. lower_frame= Frame(root, bg='#80c1ff', bd=5)
  103. lower_frame.place(relx=0.5, rely=0.5, relwidth=0.4, relheight=0.4, anchor='n')
  104. lower_label= Label(lower_frame, bg='#80c1ff', bd=5)
  105. lower_label.place(relwidth=1, relheight=1)
  106.  
  107. '''
  108.  
  109.  
  110. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement