this is my first time using stack overflow, and i would like to ask a question.
I have a tkinter window with a paned window and a canvas. I am trying to make some sort of scripting app that displays your output to a canvas. I tried multiple methods but none worked for me. Can anyone help?
This is my code:
from tkinter import *
from tkinter import ttk
from tkinter.filedialog import asksaveasfilename
from io import StringIO
import sys
class Compile(object):
def __init__(self, file) -> str:
self.file = file
exec(file)
class EditorClass:
def __init__(self):
root = tk.Tk()
root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))
button = ttk.Button(root,text='Save',command=EditorClass.save)
button.pack()
button2 = ttk.Button(root,text='Run',command=EditorClass.run)
button2.pack()
scrollbar = ttk.Scrollbar(root)
scrollbar.pack(side=RIGHT,fill=Y)
global Editor
Editor=Text(root,width=400,height=450,yscrollcommand=scrollbar.set)
Editor.pack(fill=BOTH)
scrollbar.config(command=Editor.yview)
root.mainloop()
def save():
filepath = asksaveasfilename(defaultextension="proj",filetypes=[("Text Files", "*.txt"), ("All Files", "*.*"), ("CubaScript", "*.proj")])
if not filepath:
return
with open(filepath, "w") as output_file:
global text
text = Editor.get(1.0, tk.END)
output_file.write(text)
def run() -> str:
Compile(text)
main = tk.Tk()
main.title("Cuba3D 2022")
main.geometry("{0}x{1}+0+0".format(main.winfo_screenwidth(), main.winfo_screenheight()))
hierarchy = ttk.Panedwindow(main, orient=tk.HORIZONTAL)
left_list = tk.Listbox(main)
left_list.pack(side=tk.LEFT)
hierarchy.add(left_list)
right_list = tk.Listbox(main)
right_list.pack(side=tk.LEFT)
hierarchy.add(right_list)
gameobj = ttk.Label(left_list, text="GameObject")
gameobj.pack(padx=0, pady=0)
scriptBtn = ttk.Button(left_list, text="New Script", command=EditorClass)
scriptBtn.pack(padx=2, pady=2)
ViewPortCanvas = Canvas(right_list, width=main.winfo_screenwidth(), height=main.winfo_screenheight())
hierarchy.pack(fill=tk.BOTH, expand=True)
main.mainloop()```